ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 10-29-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default Can't get value from global array

My co-worker is working on a model that makes use of global arrays. The arrays fill without a problem but when we try and return a value from the array and print it to the console it is printing 0.0000 instead of the expected value. If I write code to get the value out of the treenode it works just fine, but when I write code to retrieve a value directly from the array it doesn't work. The name of the global array is ProductNumber.

The following code works:
double x = getnodenum(rank(rank(rank(rank(rank(model(),1),7), 12),3),1));
pf(x);

The following code does not work;
double x = ProductNumber[1];
pf(x);
  #2  
Old 10-29-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Can you post a model of what you are talking about? Your syntax in that statement in fine, and all my tests are showing that global arrays are fine, so something else must be wrong in your model.

The current value of a global array is NOT found in the tree. It is stored in memory. The value in the tree is the initial value of the variable.
  #3  
Old 10-29-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

We're trying to validate the initial value, not the value set during runtime. The pf() statement was placed in the code of on OnReset trigger to test that the array had filled properly. We got the code from a post that you had made... thanks for that

See attached model.
Attached Files
File Type: zip arrayproblem.zip (100.0 KB, 242 views)
  #4  
Old 10-29-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Joe,

You are trying to dynamically change the size of a Flexscript array. Hmm. Creative. That's significantly more complicated than your original post. Thanks for posting the model so we could see what was going on in its entirety.

Your code's fatal flaw was that the information in the tree regarding what is stored in each array is string data, even if it is an array of numbers. So the refreshglobalvariables() call you are making can't figure out what's supposed to be in your array.

Attached is your model, fixed to work how you thought it should have in the first place.

In Flexsim 4.5, you can use makearray() and fillarray() on global arrays to dynamically change them easier than having to refresh all the global variables when you do it, but 4.32 is still limited in that capacity. Just a thought for your future development.
Attached Files
File Type: zip modelsendtoForum2.zip (48.4 KB, 257 views)
The Following User Says Thank You to Phil BoBo For This Useful Post:
Brandon Peterson (10-30-2008)
  #5  
Old 10-29-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

Thanks for taking a look at the model Phil. When I was looking at my co-worker's code yesterday I suspected a datatype mismatch and checked for it, but the data type that he had in the code was DATATYPE_NUMBER and it still didn't work. The model he forwarded me today to post to the forum had different code in it than the one I looked at yesterday. Sorry about that, I'll have him send me the model that we were looking at yesterday and post it.
  #6  
Old 10-29-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

OK. Please ignore my last post.

So, my understanding of your last post is that even if we have a global array of datatype Double and it has numbers in it, we have to set each treenode to DATATYPE_STRING if we want to add more dynamically and drop numbers into them.

So, if we want to dynamically fill global arrays we can only fill them with text? Is this correct? This doesn't make sense. I'm probably misinterpreting what you were saying.
  #7  
Old 10-29-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

The values in the tree are stored in "string" or "text" data - DATATYPE_STRING. The actual values stored in the actual array are what they say they are - double, int, treenode, whatever - in memory. It uses the text from the tree to create the array in memory.

The values in the tree are NOT the array. They are the values which Flexsim uses to create the array. If you change values in the tree, you are NOT changing the array; you are changing the values that Flexsim uses to create the array. refreshglobalvariables() takes all these string values and actually creates the arrays in memory, allocating the proper amount of space and putting values in according to the specified datatype: treenode, integer, double, etc.

Last edited by Phil BoBo; 10-29-2008 at 09:23 PM. Reason: less confusing terms & clarification
The Following 5 Users Say Thank You to Phil BoBo For This Useful Post:
Tom David (10-31-2008)
  #8  
Old 10-30-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

That's an excellent description of what is happnening. I hear Jimmy Cliff singing "I can see clearly now...".

Thanks Phil!
The Following User Says Thank You to Joe Allen For This Useful Post:
Phil BoBo (10-30-2008)


Thread Thread Starter Forum Replies Last Post
Limit in the completion hints? Global Tables, Global Variables, etc.? Tom David Gripes and Goodies 6 09-09-2008 04:05 PM
Assign an array to a variable AlanZhang Q&A 6 04-24-2008 01:59 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.