question

William Proctor avatar image
0 Likes"
William Proctor asked Adrian Haws edited

Using a Checkbox to Change a Global Variable

Is there a way to use a checkbox in the dashboard to change a global variable value? I can link the global variable to the checkbox but don't know how to change the global variable. I'm changing a variable called ShowFieldSegment with a desired value of "0" (unchecked) or "1" (checked). Thanks!

FlexSim 16.1.0
custom guiglobal variablecheckbox
5 |100000

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

Ben Wilson avatar image
2 Likes"
Ben Wilson answered Ben Wilson edited

The easiest way to get a checkbox to align with some value is to associate it with a node in the tree instead of a global variable:

When configured in this manner, the checkbox state (checked or unchecked) stays in sync with the tree value (1 or 0), even if some external logic changes the value in the tree, which is quite convenient and useful.

If you really must use a global variable, the automatic syncing of the checkbox state with the variable value is lost. All syncing will now have to take place manually. If there is any logic that changes the global variable's value, either at reset or during the model run, there will need to be code to also find the checkbox and sync its state (check or uncheck the box using code). You would also need similar custom logic when opening the dashboard - the checkbox would need to check the global variable's value and set its state appropriately.

The treenode method is much easier and more flexible than syncing the checkbox with a global variable. Most all the work is done for you.

----------

One of the advantages of a global variable is the ease of accessing it (its global!) and its speed. If you want to be able to query a global variable because of those advantages, I suggest a hybrid approach:

Keep your global variable, but also add a treenode. Configure your checkbox to link to the treenode, as shown above. Now you need to keep the treenode's value synced with your global variable.

Anytime you set a new value to the global variable, also set the value of the treenode. Don't forget that the global variable reverts to its default value on reset, so include a reset trigger that will sync the treenode to the global variable.

This lets you get (read) the global variable value conveniently and quickly, but by syncing with a treenode each time you set (write) the global variable, you keep the benefits of syncing the checkbox with a treenode - its kind of a double-sync: you keep the treenode synced to the global variable, and FlexSim automatically keeps the checkbox synced.


dashboardcheckbox.gif (896.2 KiB)
· 1
5 |100000

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

William Proctor avatar image William Proctor commented ·

Thanks! Works great.

0 Likes 0 ·
Matt Long avatar image
0 Likes"
Matt Long answered

This appears to be a bug. It should allow you to tie a checkbox to a Global Variable. We'll put this on this list to be fixed. Thanks.

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.