I have an array declared as a scene variable, in the middle of the code, every time I press a button a series of commands is executed, among them I want that every time the button is pressed, the 0 position of the array is eliminated.
For example, if I have the array [23,45,12] when pressing the button once it would stay in [45,12]
To do this I use the function Remove variable by index, to delete the 0 position and it does it correctly.
The problem is when only one value remains in the array, [12], when executing the function sometimes it does it correctly and converts the array to empty, and other times what it does is convert that last value to [0], but does not delete it.
Any idea why this behavior can happen? Am I using the right function?
The problem is this second line, That serves to assign the value poolLevels[0] to a variable. It does it correctly but when the array is empty, what it does is create a new value to read it, thats why never remove this last item, because “changue de variable” creates again with zero value. is it a mistake or am I going crazy?
(I have put this second line here followed to facilitate reading, but it was very much within an external event code…)
OMG, hours spent on this XD. I could imagine that it returned error or 0, but not that it added anything to the array. Is this a normal and plausible behavior?
It’s a normal behaviour of GDevelop. Previous versions of GDevelop had it so if a variable was referenced and didn’t exist, it would be created with a default value of 0.