question

Craig DIckson avatar image
0 Likes"
Craig DIckson asked Matt Long commented

Radio buttons to change a global variable

I would like to change the value of a global variable to either 1 or 2 or 3 from the dashboard. I tried it with radio buttons. I added three radio buttons, linked the first to the variable from the pull down, linked the other two buttons to the first one, and set each one's value. Took them out of edit mode, and nothing happens. Any suggestions on what I missed?

FlexSim 16.2.0
dashboard button
5 |100000

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

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

Looks like the Radio Button is not set up to work with the Global Variables even though it gives you that option in the Link. We'll add this to the dev list.

In the mean time, if you're just needing to set the variable you can add code to the OnPress trigger of the Radio Button to set the variable:

myVariable = 1;
· 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.

Matt Long avatar image Matt Long commented ·

You can change a Radio Button's state in a dashboard externally through code using the following:

setchecked(getdashboardcontrol("RadioButtonID"), 1); //Check
setchecked(getdashboardcontrol("RadioButtonID"), 0); //Uncheck
0 Likes 0 ·
Ben Wilson avatar image
0 Likes"
Ben Wilson answered Ben Wilson edited

@Craig DIckson,

@Matt Long's simple bit of code will update the Global Variable's value, but the Dashboard widgets' states can easily fall out-of-sync with the GV's value. For instance if you reset the model, the GV value is reset. Or if some object in your model modifies the GV's value. In both cases, the GV's value changes, but the Dashboard widget will not change to reflect the GV's current value.

To keep the Dashboard state and the Global Variable value in sync, consider using the tree as a go-between.

For more info, check out the this Q&A:

https://answers.flexsim.com/answers/25774/view.html

5 |100000

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