Connecting to a function with arguments

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RebiDesi

Alright, so you used to be able to connect with connect(signal, node, function, [methods])

Now I see connections have been changed to connect(signal, "callable"), how do I fix this to work with methods?

:bust_in_silhouette: Reply From: zhyrin

Every method is a callable.

# receiver.gd
func callback(parameter) -> void:
    pass

# sender.gd
signal my_signal(parameter)

func _ready() -> void:
    var receiver = get_receiver()
    my_signal.connect(receiver.callback)

func procedure() -> void:
    var value = ...
    my_signal.emit(value)

I found the proper way to do it which is connect(signal, function.bind(method))

RebiDesi | 2023-03-22 05:12