ATTENTIONThis 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 |
#1
|
||||
|
||||
Assign an array to a variable
Is there a way to assign an array to a variable? For example, if I define arrays in the Global Variables, then I want to assign these arrays to a local variable. I tried something like:
treenodearray a1; a1 = globalA1; The above code won't compile and Flexsim just silently (without popping-up) output a message: "Could not finish parsing because of previous errors." in the compile window and won't tell you which line causing the problem. Then I think maybe I can create a command to copy the array. But since I cannot pass array as a parameter, this is not an option either. Any idea? Since array is such a common type in a programming language, I really think the array operations should be improved for the next release of Flexsim. Thanks.
__________________
Best, Alan |
#2
|
||||
|
||||
Look up the command makearray in the command list. It should help you further . If you use:
treenodearray a1 = globalA1; it should work. Martijn |
#3
|
||||
|
||||
Thanks Martijin.
The following code work: Code:
intarray a1=makearray(2); fillarray(a1,1,2); intarray a3=a1; for(int i=1;i<=2;i++){ pd(a3[i]);pr(); } Code:
intarray a1=makearray(2); fillarray(a1,1,2); intarray a2=makearray(2); fillarray(a2,3,4); intarray a3=a1; int con=1; if(con) a3=a2; for(int i=1;i<=2;i++){ pd(a3[i]);pr(); }
__________________
Best, Alan |
#4
|
||||
|
||||
In the second case you've already defined the integer array as a copy of a1. If you want the values of a2 to be copied again afterwards you can use a for loop as you did to print the values:
for( int i = 1; i <= 2; i++ ) { a2[i] = a3[i]; } you can put this in a user function and if you like. Martijn |
#7
|
||||
|
||||
This thread gives an example of working with multi-dimensional arrays in flexscript that you might find useful.
|
Thread | Thread Starter | Forum | Replies | Last Post |
Which variable stores "Properties -> General ->Flags -> Protected" information? | KelvinHo | Q&A | 1 | 03-06-2008 06:18 AM |
Display Global Variable | Sung Kim | Q&A | 4 | 02-24-2008 11:24 PM |