#Button signal, antiquated data
17 messages · Page 1 of 1 (latest)
Just to confirm what you're saying— you initialized some_data to something (i.e. 1), clicked the button, got 1, set some_data to something else (i.e. 2), clicked the button again, and got 1 still?
Yeee
Youd need to pass a variable that is passed by reference
If it is an integer for example you just pass a copy of the value at the time of the binding
Upon further inspection it seems like this same phenomenon is occurring at all the points where the data is being used. It's in a separate script which is added to autoload. All of my code is referencing it directly
What is the specific goal actually ? How youd set the signals and callbacks up depends on it kinda
Hard to say with all my spaghetti I have made, but If I had to say one goal I am trying to figure out how to do it would just be: How to avoid passing by copy, if I want by reference. In general
This is pretty confusing because the thing I am passing is a dictionary so I was assuming it would be by reference in gdscript
If you use a dictionary then you could assign a key with bind and read the value that can change inside the function
Weird though that you pass a dict and it doesnt change.. Maybe the problem lies somewhere else
But youd have to show what exactly you do for me to figure that out 😅
I think it probably is somewhere else. Do you know if passing as an argument would make something a copy instead of reference normally?
As i wrote here:
- Reference:
Array,Object,Dictionary, packed Arrays - Copy: Everything else
It´s also a common error if you think an array is a copy you assign it to another variable and change it, Both variables will have a reference to the same array.
To pass a copy for those youd need to use the .duplicate() method
var my_array = [1,2,3]
var my_other_array = my_array
var my_other_other_array = my_array.duplicate()
my_other_array[0] = 999
my_other_other_array[0] = 123
prints(my_array,my_other_array,my_other_other_array ) # //[999, 2, 3] [999, 2, 3] [123, 2, 3]
Oh this is interesting, I shifted the passing of the dictionary to outside of the function parameter and it now works by reference and not a copy. Maybe there's a weird bug happening
This might be a case of "closures" / anonymous functions.