How to pass arguments to a timer function

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

Hi there,

How can I pass arguments to a timeout function inside of Godot v4.0.1.stable.
Kind of like this:
gun_fire_timer.timeout.connect(on_gun_fire(arg1, arg2, arg3, arg4))
so that in the function on_gun_fire I can access arg1, arg2…

Currently this does not work. It just gives out the error :
“Cannot convert argumnent 2 from Nil to Callable”

Thank you in advance…

:bust_in_silhouette: Reply From: jgodfrey

You need to use the bind method of the callable. In practice, that just requires this simple change to the above:

gun_fire_timer.timeout.connect(on_gun_fire.bind(arg1, arg2, arg3, arg4))

Thank you :slight_smile:

Borna | 2023-06-30 15:03

:bust_in_silhouette: Reply From: spaceyjase

You need bind the args to a Callable and pass that to connect.

var callable = Callable(self, "on_gun_fire").bind(arg1, arg2, arg3, arg4)
gun_fire_timer.timeout.connect(callable)