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 04-24-2008
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default 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  
Old 04-24-2008
Martijn van Oostenbrugge's Avatar
Martijn van Oostenbrugge Martijn van Oostenbrugge is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 71
Downloads: 12
Uploads: 0
Thanks: 44
Thanked 44 Times in 24 Posts
Rep Power: 268
Martijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to all
Default

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  
Old 04-24-2008
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

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();
}
The following code won't work:
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();
}
So you could not really assign an array to a variable. Problem remains.
__________________
Best,
Alan
  #4  
Old 04-24-2008
Martijn van Oostenbrugge's Avatar
Martijn van Oostenbrugge Martijn van Oostenbrugge is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 71
Downloads: 12
Uploads: 0
Thanks: 44
Thanked 44 Times in 24 Posts
Rep Power: 268
Martijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to all
Default

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
  #5  
Old 04-24-2008
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Can I pass an array into a user command? How?
__________________
Best,
Alan
  #6  
Old 04-24-2008
Martijn van Oostenbrugge's Avatar
Martijn van Oostenbrugge Martijn van Oostenbrugge is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 71
Downloads: 12
Uploads: 0
Thanks: 44
Thanked 44 Times in 24 Posts
Rep Power: 268
Martijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to all
Default

I was thinking to pass a value and call the user command for each value you set, but that wouldn't make sense.

Martijn
  #7  
Old 04-24-2008
Cliff King's Avatar
Cliff King Cliff King is offline
Vice President Technical Services
 
Join Date: Jul 2007
Location: Utah
Posts: 272
Downloads: 158
Uploads: 14
Thanks: 102
Thanked 304 Times in 110 Posts
Rep Power: 412
Cliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud of
Default

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


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.