extends Node
...
signal my_signal
func _ready():
connect("my_signal", self, "signal_handler")
...
var otherNode = get_node("someNode")
otherNode.connect("my_signal", self, "signal_handler")
func SomeFunc():
...
# causes self.signal_handler() to be called
emit_signal("my_signal")
...
func signal_handler():
...
edited
Ok, so a signal is declared like that
I figured out that emit_signal("my_signal") works, but emit my_signal is seen as an error.
Zylann | 2016-04-19 00:28
Sorry! Edited now.
duke_meister | 2016-04-19 00:31
all you really have to do is this for simpler programs
signal SignalNameHere
then use the editor to connect to target
wherever you want the signal to “emit” put
emit_signal(“SignalNameHere”)
and voila
I recommend it is used for simpler programs as this requires you to connect the signals when with more complicated ones the program may have to do it itself. So hears the code.
signal SignalNameHere
func _ready():
emit_signal("SignalNameHere")