how to pass argument from the signal to the function ?

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

how to pass argument from the signal to the function ?

:bust_in_silhouette: Reply From: Inces

There are 2 main ways of binding aruments to the signal

  1. On connection.

(This makes gun send reference to itself along every signal it will emit towards script above. These binds are in brackets, they must be in array)

  1. On emission

(This makes every emitted signal carry information about current ammo, at the moment of emission. This can be any number of different variables, spearated by comma.)

Finally, connecting method reads these arguments from brackets, first binds on emission, next binds on connection :

func on_gunshot(ammo, gun):
         if ammo == 0:

Wait are you sure this syntax is correct for Godot 4.x? I thought this is the syntax for connecting signals in Godot 4.x


bonsaipropaganda | 2023-04-16 05:28

This is a post from 2021, there was no Godot 4 back then. I don’t understand how it was tagged “Godot 4” in question retrospectively.

Inces | 2023-04-16 09:48