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.


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.

Braydn T avatar image Braydn T commented ·


I have never used hot links, but I would just have an if statement like this:

This code triggers every time the button is pressed

if(globalVar == someVal){

set globalVar to new val;


set globalVar to someVal


You may also want to use a normal button instead of a checkbox.

-1 Like -1 ·
Sebastien avatar image Sebastien Braydn T commented ·

Hi @Braydn T,

I tried that in the model I attached, but the data type seems to not be right although I specified integer in the code. Moreover I would like to stick with the checkbox as it is more user friendly for activating deactivating things.

0 Likes 0 ·

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.

if (eventdata) { // applying
	checkboxHotlink = getchecked(c);
} else { // refreshing
	setchecked(c, checkboxHotlink); 

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

treenode glbvarSetup = Model.find("MODEL:/Tools/GlobalVariables/checkboxHotlink/Data");

if (eventdata) { // applying
	glbvarSetup.value = string.fromNum(getchecked(c));
} else { // refreshing
	setchecked(c, glbvarSetup.value.toNum());


5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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