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"

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?

in Engine by (254 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
by (10,467 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.