GODOT- MASS Connecting a lot of Button to the Same Function
There are some cases in which we need to get the current object and manipulate the functions. Mass connecting a lot of buttons to the same function is one such case.
In GODOT to know which button is been pressed and manipulate the function accordingly, we need to first group buttons.
Click the particular button and select the node. Under node, you have signals and groups. Add a new button group says “letter_button”. Repeat the same for every button you need to process.
Then in script add the following
func _ready():
for button in get_tree().get_nodes_in_group("letter_button"):
button.connect("pressed", self, "_which_button_pressed", [button])
func _which_button_pressed(button):
button_name = button.name
print(button_name
Now when you click the button, it will print the name of the currently pressed button.



Post a Comment