question

Sebastien avatar image
1 Like"
Sebastien asked Phil BoBo edited

Model Control GUI not updating the global variable

I am trying to build a GUI with a checkbox linked to a global variable. When users click on the checkbox it should automaticaly update the global variable.

I saw a similar post in the forum about a checkbox in the dashboard GUI. I tried implementing this solution with a simple hotlink but when I click on the checkbox it does not change the global variable and when I open the Main Control GUI again the checkbox is checked. As if the hotlink does not allow to change the variable but the variable change change the state of the checkbox.

I also tried with a bit of code to manually change the global variable with "On Press" in the GUI. I could change the data but it switches from 1 to 0.00 and then 1.00. So maybe the data type changed also I asked for an integer in the global variable and in the GUI.

I don't understand where is my mistake.

Here is a sample model with the problem.

global-variable.fsm

FlexSim 20.0.1
guiglobal variable
global-variable.fsm (23.4 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo edited

The value in MODEL:/Tools/GlobalVariables/GlobalVariableName/Data is the Reset Value of the global variable. It must always contain String data and stores the value that will be set on the global variable when you reset the model.

Your checkboxes are trying to change that value. The OnPress one is incorrectly setting the datatype to a number, and the hotlinked one doesn't work correctly because a hotlink on a checkbox only works with a number node, not a string node.

Are you trying to set the value of the global variable or the reset value of the global variable?

If you are trying to set the value, then you should write hotlinkx code that sets the global variable directly.

  1. if (eventdata) { // applying
  2. checkboxHotlink = getchecked(c);
  3. } else { // refreshing
  4. setchecked(c, checkboxHotlink);
  5. }

If you are trying to set the reset value, then you should write hotlinkx code that gets or sets that node as a string.

  1. treenode glbvarSetup = Model.find("MODEL:/Tools/GlobalVariables/checkboxHotlink/Data");
  2.  
  3. if (eventdata) { // applying
  4. glbvarSetup.value = string.fromNum(getchecked(c));
  5. } else { // refreshing
  6. setchecked(c, glbvarSetup.value.toNum());
  7. }

checkbox-ui-link-to-global-variable.fsm


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.