0 votes

I have a grid of 81 buttons, all of them perform a similar function, only differing slightly depending on which button was clicked, for example, clicking the button will set it's text to "clicked". I thought there was probably a way to have all of them signal to one function, but pass a different argument, something like this

button 1 - buttondown connected to "action()" passing the argument "one"
button 2 - button
down connected to "action()" passing the argument "two"
etc...

But I'm not sure how to connect a lot of different signals to the same function, passing different arguments. How might I do this?

asked Jun 14 in Engine by psear (103 points)

1 Answer

+1 vote
Best answer

You can do this when you connect signals from code:

func _ready() -> void:
    $Button1.connect("button_down", self, "action", [$Button1, "one"])
    $Button2.connect("button_down", self, "action", [$Button2, "two"])

func action(button : Button, new_text = String) -> void:
    button.text = new_text
answered Jun 14 by njamster (8,874 points)
selected Jun 15 by psear

This is what I was looking for, thanks.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.