Help with connecting a variable argument to a custom signal

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

GODOT REFERENCE VERSION: V3.0.6.stable.official.8314054
Howdy everyone, been a while, I am trying something that should be simple enough. But I keep facing a mysterious response, here’s my code:

    $MyButton.connect("ButtonClickedFunction",self,"MyCustomFunction", [GLOBAL_ITEM,1])

#In short, MyCustomFunction deletes an item, this item is stored in GLOBAL_ITEM, and the quantity to delete is 1.

But it if I print the function argument 1:

print(ItemToDelete)#To check what is returning in that connect code above.

This returns always the default value I stored in the global var despite any changes I make later, like an item select updating the GLOBAL_ITEM.

Do the connection with arguments only are defined once? Like constants?

Because printing only the global variable it displays any changes I made it later to GLOBAL_ITEM, but not when the Signal Function connect calls it.

Any tips?

Thanks in advance,

:bust_in_silhouette: Reply From: timoschwarzer

If you do it like this, you will always pass the value that GLOBAL_ITEM has when connecting the signal. You are passing GLOBAL_ITEM as value, not as a reference. You want to access GLOBAL_ITEM in the target function or pass it when calling emit_signal(...) instead of passing it as a signal parameter.