0 votes

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:

func_ready():
    $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:

MyCustomFunction(ItemToDelete,QuantityToDelete):
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,

asked Dec 27, 2018 in Engine by The_Black_Chess_King (265 points)

1 Answer

+1 vote
Best answer

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.

answered Dec 27, 2018 by timoschwarzer (700 points)
selected Dec 27, 2018 by The_Black_Chess_King
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.