Check if a variable is set

I have an array (with text entries) from which I have to take index 0 and then delete it, so that the array “scales” automatically.
So I have to detect if the “myarray[0]” variable is set or not.
I tried the command:

The text of the global variable myarray[0] [disegual] “”

However, it is always activated by returning “0” as a string.

… Is there a way to indicate the empty or unset string?

Yes, GDevelop does that - if you refer to an undefined variable, it will create it and set it to a default value of 0 (or false).

An array is empty if it has no children. This isn’t intuitive to test (it’s not under Variables) - you need to use the compare 2 numbers function :

image

and use the VariableChildCount function :

image

1 Like

…Very unintuitive!

Thank you!

I’ve requested something more intuitive :smiley:

Did you try the Extended Variables extension?

…What Extended Variables?
I’m newbie here.

In the Project Manager > Function/Behviors > Search for new extensions > Search for : Extended Variables

It checks if the variables exist without affecting it, so with these new actions/conditions if the variables don’t exist, there is no default value, and the variables aren’t initialized to “” or 0.

2 Likes