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:

    $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,

in Engine by (360 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.

by (698 points)
selected by
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.