Toggle visibility scripting help

Godot Version

4.2.2

Question

Untitled

This is my script, I have a menu with two toggle buttons that I am trying to work with. My goal I am attempting is that when toggled on, the menu in question is visible, when toggled off it is no longer visible.

Now in a way my current script “works” but rudimentarily as I need to toggle the other button one to make the other menu nonvisible.

Trying to toggle on makes it visible, trying to toggle off non-visible.

Online tutorials are lacking in-depth description.

Thank you

I am not 100% sure I am following the issue here but I will take a stab at it.
In theory the toggled_on parameter in both of the functions is true when that button is toggled on and false when it is toggled off.
So I think your code should look like this:

func _on_setup_toggled(toggled_on): 
    get_node("MarginContainer/setupTabs").visible = toggled_on   
    get_node("MarginContainer/settingTabs").visible = !toggled_on

func _on_settings_toggled(toggled_on): 
    get_node("MarginContainer/settingTabs").visible = toggled_on   
    get_node("MarginContainer/setupTabs").visible = !toggled_on

However the ButtonGroup is designed to be used when items are exclusive ie when only 1 option is allowed.

PS: Pictures of code are less desirable than copy pasted code here (and in any forum). The main reason being people replying to you must retype your code.

You can select both buttons and give them a new button group

Thank you, I’m used to people asking for pictures. I will type it out for next herlp request.

I didn’t understand “toggled_on” and how it worked. sorry, I feel like an idiot.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.