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
|
||||
|
||||
Change Global Variable Permanently
Hello.
I am trying to find a way to code in GUI changing global variable permanently. Right now, the GUI code works like below. If I click the set button, this set button has a trigger "onPress." Here, onPress, I coded "globalVariable = 1;" However, the default setting of this globalVariable is 0. If I open the script window and check this value after I click the set button, the value is changed. But if I just open the menu > tool > global variable and see the value of this globalVariable there, the value is still 0. Is there any way to hard code to change this default setting value of globalVariable so that the change should be set even if I reopen the model? Thank you. |
#2
|
|||
|
|||
set initial value of global variable
To set the initial value of the 4th ranked global variable to a value of 55 you could use:
setnodestr(last(node("/Tools/GlobalVariables/4",model())),"55"); Note that the value is a string, and it will NOT set the current value of the global variable... you know how to do that. However, this will stick if the model is saved and reopened. Explore the model Tree under Tools/GlobalVariables to understand why this works. Also, some commands you might want to look into: refreshglobalvariables() numtostring() Also, this post: /threads/thread729 |
The Following User Says Thank You to Kris Geisberger For This Useful Post: | ||
Chris Moon (04-11-2011) |
#3
|
||||
|
||||
Thanks, Kris Geisberger
I really appreciate it.
Kris Geisberger, I have one more question for you. I know the code below works for 4th ranked global variable. setnodestr(last(node("/Tools/GlobalVariables/4",model())),"55"); What if the 5th ranked global variable (AvgNum) is double array and I want to change the 2nd array value of this global variable(AvgNum[2]), what code should I use? I look forward to your answer. |
#4
|
|||
|
|||
You will see in the attached screenshot that the Data node is the last (3rd) child node of a given variable. The 2nd variable in this case is a double array of 4, and you can see that the Data node of the 2nd variable has 4 child nodes to hold the initial values of the array.
I'll give examples for setting the 4th initial value of the 2nd variable (a double array). setnodestr(rank(last(node("/Tools/GlobalVariables/2",model())),1),"55"); setnodestr(node("/Tools/GlobalVariables/2/3/1",model()),"55"); |
The Following User Says Thank You to Kris Geisberger For This Useful Post: | ||
Chris Moon (04-11-2011) |
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 & task sequence | Chris Moon | Q&A | 1 | 03-02-2011 10:46 AM |
Show global variable as line graph in Recorder | Congshi Wang | Q&A | 1 | 12-08-2010 01:22 AM |
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 |