0 votes

Hi everyone,

this must be rather essential. I have several nodes, all emitting the same signal that I can catch via var getsignalbutton_down.

Now, with this setup

func _ready():
    get_signal_button_down = get_tree().get_root().find_node("CheckBox1Base", true, false)
    get_signal_button_down = get_tree().get_root().find_node("CheckBox1BaseX", true, false)
    get_signal_button_down = get_tree().get_root().find_node("CheckBox1Base3", true, false)
    get_signal_button_down = get_tree().get_root().find_node("CheckBox1Base4", true, false)
    get_signal_button_down.connect("button_down", self, "button_down_received")

func button_down_received():
    print ("button down")

I can only make one of them print when I # the others. But why is that so and how can I have them all printing?

And then there must be a way to merge them all together in one line, right? Unfortunately, the intuitive thing get_signal_button_down = get_tree().get_root().find_node("CheckBox1Base", "CheckBox1Basex", "CheckBox1Base3", "CheckBox1Base4", true, false) doesn't work. How could I make this more compact?

The fabulous fabulousmaximus nailed it:

for x in ["CheckBox1Base", "CheckBox1BaseX", "CheckBox1Base3", "CheckBox1Base4"]:
    var get_signal_button_down = get_tree().get_root().find_node(x, true, false)
    get_signal_button_down.connect("button_down", self, "button_down_received")
in Engine by (381 points)
edited by

Please log in or register to answer this question.

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.