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 12-16-2012
Vadim Fooks's Avatar
Vadim Fooks Vadim Fooks is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 67
Downloads: 26
Uploads: 0
Thanks: 50
Thanked 24 Times in 13 Posts
Rep Power: 118
Vadim Fooks will become famous soon enough
Default Is passing array arguments to nodefunctions acceptable?

Greetings, ladies and gentlemen!
I am trying to figure out the right way of passing a variable number of parameters to a nodefunction.
I have put together the following piece of code for testing, and it appears to work, but is this the proper way and is it handled correctly internally?

Code:
//TestArrayArgs(int argc, intarray argv)
int argc = parval(1);
int argvPtr = parval(2);
intarray argv = argvPtr;
for (int ii = 1; ii <= argc; ii++)
{
 pt("Arg #"); pd(ii); pt(": "); pd(argv[ii]);pr();
}
Code:
intarray ia = makearray(5);
for (int i = 1; i <= 5; i++)
 ia[i] = i *57;
int  blah = TestArrayArgs(5, ia);
* Is there a similar way to allocate and populate an array in the nodefunction, cast it to integer and return from the function?
* Is there a way to tell the number of elements in the array from the pointer?


Thank you!
Vadim
  #2  
Old 12-17-2012
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

In prior versions of FlexSim, you couldn't pass arrays in Flexscript. You had to store information in nodes in the tree and pass a reference to the parent node in order to get more information passed between functions.

In version 6.0.2, it appears as though returning arrays in a Flexscript user command somewhat works. I tested creating an intarray of size 500 and return it from a user command. When I try to access the array from within the script window, indexes 0 and 1 return bad values, but 2-500 work properly.

I suspect this development was started but not finalized, which is why it never appeared in release notes. I will discuss this with the rest of the development team to figure out what the plan is with array return values and parameters in Flexscript.

I suggest continuing to store information in nodes in the tree and pass a reference to the parent node in order to get more information passed between functions.

Last edited by Phil BoBo; 11-19-2014 at 05:52 PM.
The Following 8 Users Say Thank You to Phil BoBo For This Useful Post:
Vadim Fooks (12-17-2012)
  #3  
Old 12-18-2012
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

After discussing this with the rest of the development team, I have found that this functionality was not implemented intentionally. It is simply a by-product of how we store and pass parameters and return values. Although reading and writing to this memory using this syntax appears to mostly work, the memory that it is pointing to might have been deallocated by flexsim, which may cause unexpected results when you read/write to it (particularly if another process happens to allocate that memory by chance).

I strongly suggest not returning arrays in Flexscript and not passing arrays as parameters in Flexscript. A safer way to pass more information is to store it in the tree and reference it with treenode pointers.
The Following 5 Users Say Thank You to Phil BoBo For This Useful Post:
Vadim Fooks (12-18-2012)


Thread Thread Starter Forum Replies Last Post
How to debug nodefunctions? Vadim Fooks Q&A 4 09-25-2012 01:55 AM
array size juan alberto Q&A 0 12-21-2010 03:03 AM
Passing parameters in executefsnode Sung Kim Q&A 2 06-01-2010 09:37 AM
Passing strings into a usercommand Nico Zahn Q&A 6 01-13-2010 11:20 AM
Can't get value from global array Joe Allen Q&A 7 10-30-2008 09:06 AM


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.