Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | pferft |
Hi everyone,
this must be rather essential. I have several nodes, all emitting the same signal that I can catch via var get_signal_button_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?
ANSWER:
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")