How to save the state of a checkButton?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NoTheOtherMatt

I have a checkButton, that when toggled, turns on or off hard mode in my game. The checkButton is in my Options Menu scene, and it changes the hard_mode variable in my GlobalVar AutoLoad script from True to False or False to True. However, when I leave the Options Menu scene and return, even if the checkButton was toggled to on, it now shows off. It doesn’t actually change my variable, but I want the button the stay on if I turn it on.

Can I just put in an if statement that looks at the hard_mode GlobalVar and if true show toggled if false don’t toggle?

my GlobalVar path is $“/root/GlobalVar”.hard_mode

How are you toggling it? You should have the button_down() signal connected and GlobalVar.hard_mode = !GlobalVar.hard_mode

Magso | 2020-09-05 14:31

It toggles with a left click, and sends a signal to the options menu

func _on_CheckButton_toggled(button_pressed):
$“/root/GlobalVar”.hard_mode = not $“/root/GlobalVar”.hard_mode

NoTheOtherMatt | 2020-09-05 14:42

:bust_in_silhouette: Reply From: vanyousee

Yes, the variable should have been changed.
It is because resources are static, if you save the menu instance with a variable and toggle its visibility instead of call instance() method when you enter menu, any changes on the menu instance should remain.

I’m not sure I understand what you mean. I don’t want to change if the button is visible, I want to change if it shows on or off.

NoTheOtherMatt | 2020-09-05 13:56