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
FAQ Downloads Calendar Search Mark Forums Read

Q&A Using Flexsim and building models

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-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: 115
Vadim Fooks will become famous soon enough
Default 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();
}
....
The problem is that the task sequence code will fail when the operator has been moved into the transporter and its path changes to /Transporter/Operator.



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
Reply With Quote
  #2  
Old 11-14-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 771
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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.
Reply With Quote
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
Vadim Fooks (11-14-2012)
  #3  
Old 11-14-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: 1172
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

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))
Reply With Quote
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
Jörg Vogel (11-15-2012), Vadim Fooks (11-14-2012)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -6. The time now is 08:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.