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 |
|
Downloads |
Q&A Using Flexsim and building models |
#1
|
||||
|
||||
Is it possible to make a label point to a global variable?
Question:
is it possible to do the following: 1) Create a global variable of type treenode pointing to an object 2) Specify the name of the global variable in a label of another object, so it can interact with the first one even when the object gets moved in the tree at runtime without directly referring to the global variable by its name. Example: The model consists of objects: /Controller /Operator /Transporter In the course of the execution of the task sequence implemented in the /Controller, the Operator is moved in and out of the Transporter. The end user configures the controller by creating a text label "OperatorToUseInTheTaskSequence" and setting it to a value "/Operator". In the code of the task sequence I access it by using the following code: Code:
string op = getlabelstr(current, "OperatorToUseInTheTaskSequence"); treenode opPtr = node(op, model()); if (!objectexists(opPtr)) { msg("Fatal error","....."); stop(); } .... Background: I am developing a library component implementing a complex task sequence. The end user of the component integrates it into the model by setting the label values pointing at the objects taking part in that task sequence. Problem is that some of those components at runtime can be moved in and out of other objects, so static pointers no longer work. In order to overcome that problem I am trying to require the end user to create a global variable for each object and set the labels on the "control" object from the library to point at those global variables so I can use them at runtime without knowing what they are. If I was designing a model rather than a library, I would have simply used a global variable and had FlexSim engine take care of this, but I have to give means of customization to the end user in some way. The problem would be solved if I could have the end user create a global treenode variable MyOperator and set the label to point to the global variable, but how do I access the global variable by name? I cannot just create global variables and have the end user populate the values because the end user configures the number of participants. Thank you! Vadim |
#2
|
|||
|
|||
This is what centerports and dispatchers are for - but I can see why you might want something else.
If global variables don't work for you perhaps some group functions would help you. Or a different way of referencing objects and their relationships to each other. |
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Vadim Fooks (11-14-2012) |
#3
|
||||
|
||||
You could also give your label coupling data and point it to the object you want to reference rather than giving your label string data and getting the object by path.
(The user selects the object by path, and then your code stores a pointer to the object in coupling data and later references it with the get() command.) Code:
//store the pointer nodeadddata(thelabel, DATATYPE_COUPLING); nodepoint(thelabel, theobject); //get the pointer treenode theobject = tonode(get(thelabel)) |
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Vadim Fooks (11-14-2012) |
Thread | Thread Starter | Forum | Replies | Last Post |
global variable in DLL (UserFuncs.h) | Esther Bennett | Q&A | 7 | 09-12-2012 07:02 PM |
Global Variable resetting | Bill Lank | Q&A | 3 | 05-25-2012 10:47 AM |
Change Global Variable Permanently | Chris Moon | Q&A | 3 | 04-11-2011 07:46 PM |
Global variable as experiment variable | Matthias Hofmann | Q&A | 3 | 09-08-2009 09:42 AM |
Display Global Variable | Sung Kim | Q&A | 4 | 02-24-2008 11:24 PM |