How to check if a variable inside a structure exists without creating it?

Hey guys,

I have the following code for my character selection screen that checks if you own the characters.

Basically on a different screen, once you unlock a character, the game creates a Structure, included the following children: copies that you own, character level, MasterOwned (Boolean to check if you own the character)

I noticed, that even if you do not own the character, once I do the below action Gdevelop will create the structure without my permission, most likely to check if it exists? See the below example

I found the Extended variables extension and tried to use this action instead, but it still creates the variables without my permission

image

Any ideas?

Okay so right after creating the post I noticed that I can solve my issue with this. Not the solution I was looking for but oh well.

image

Still not sure why Gdevelop can create variables from the conditions section… I guess this is the way that the engine works? Maybe to avoid crashes if something does not exist? If someone could explain it I would appreciate it.

Also why does this thing exist if it’s going to create the variable that you are searching for anyway?

The Extended variables extension is old. It seems to be for checking if a variable exists not a child. There was a time when variables didn’t need to be declared to be used. Not just a child variable but the entire variable.

My guess is that the extension doesn’t create the structure but using the variable with the structure as a parameter is creating it. It’s no different from using a structure with any other event except for the condition that checks if the child exists. Even that condition doesn’t actally use the entire variable name. It breaks up the variable and the child name.

As you guessed, GD creates variables to avoid crashes. Otherwise, it might return a null or other error.

Your solution seems to be good.

Another option is to create the structure with default values. Then you could check if the variable is true or false. If the structure is declared then it’s easier to use the autocomplete feature when writing code.

1 Like

Thanks, that makes sense.

Feels like yesterday when we could use variables without declaring them.

I don’t want to create the structures on my own because there are a lot of characters, that’s too much work :stuck_out_tongue:

1 Like