How to toggle a button in script

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

I want to be able to click a button and toggle it on and then click another button to toggle it off. But how do i set a button thats set to toggle mode back to neutral using script

_button.pressed = not _button.pressed

rakkarage | 2020-06-05 14:14

:bust_in_silhouette: Reply From: MaaaxiKing

If your scene tree looks like this:
Any node with script attached

Button1 (Toggle mode active)
Button2 (signal _on_Button2_pressed connected to the root node’s script)

In the script:
extends Node (or whatever node your root node is/the node this script is attached to)

	$Button1.button_pressed = false

I’m not sure if it’s been removed in later versions, but Godot 3.5 doesn’t have a Button.button_pressed property, it’s now just called “pressed”.

SteveSmith | 2023-03-10 07:32