How to untoggle buttons when another button is pressed?

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

So, I have three buttons: casual, adventure, and extreme.

I can’t figure out how to script them so that only one can be toggled. I want it so I can’t toggle both casual and adventure or all of them at the same time. I tried using signals, but they don’t seem to work

:bust_in_silhouette: Reply From: Gerardo Gonzalez

A Checkbox button has a property for that, the TOGGLE MODE under BaseButton section, also you can use the ICONS section under Theme Overrides and put your own icons for a toggle mode.

Just loop an array with your buttons to reset the pressed mode for each button
and set up your desire button in pressed mode.

:bust_in_silhouette: Reply From: jgodfrey

If you assign any number of buttons to a common ButtonGroup, they will effectively become radio style buttons, allowing only 1 to be pressed at a time. For example, if you create 3 Buttons and set their toggle_mode to true. Then, do something like:

func _ready():
	var grp =
	$ = grp
	$ = grp
	$ = grp

That should get you close to the behavior you want (note, you can also use CheckButton in place of the above Buttons).

I tried it and it works! Thank you!

jazzix | 2023-01-21 12:22

1 Like