I just started to use Godot and I’m a bit confused about the usage of signals. As far as I understand there are two ways to use Signals, but one of them might be unintended?
Defining a Signal, than passing it down to a Button for example and awaiting the Signal.
signal baz
func _init():
var foo = Foo.new(baz)
game_loop()
func game_loop():
while(true):
await baz
class Foo:
extends Button
var bar: Signal
func _init(p_bar: Signal):
bar = p_bar
func _pressed():
bar.emit()
I’ve been using the first example to generate multiple buttons in a menu that use the same signal to notify an Object, but I get the feeling that it is the wrong approach. Also… I didn’t test that code example. It might not be 100% correct.
Connecting a signal this way would also make the children signals “private” with the parent. If done the proposed way above, adjacent Nodes to the parent could also listen for that signal of the buttons as a side effect of the child emitting on behalf of the parent. (Maybe parent child is incorrect, it could be delegate and owner of signal)
But if you had such a need to do this you could also just have a cascade of emitting signals. One from the button, then one from the parent that a button was pressed.
…
I don’t know if that while loop is just for demonstration purposes, but seems like an anti-pattern for how signals want to work. Just connect a callable function to the signal.
Ohhh… I don’t know why I was so stuck on using the while loop. There is no need to await the Signal if there is no loop. Just connect the methods. Thanks. Im new to Godot and Game developement in general. Sorry if the question was stupid. Just one more question.