[Solved] Can I use a variable as a part of another variable's name?

Hello~

I have a question about variable.

The variable looks something like this.


Example:
GlobalVariable(character_score1)


What I want to do is replacing the text ‘character’ with ‘a variable’.
Because I have lots of characters in my game.


To something like this.
GlobalVariable(GlobalVariable(character_name)_score1)


But I’m keep getting an error message.

Is there a way to make this work? Thank you!!

you can use arrays/structures


wiki: Variables [GDevelop wiki].

1 Like

ohhh!! :exploding_head: :exploding_head: :exploding_head: This could be so convinient!! Thank you so much!!!

1 Like

To put “a variable in a variable”, access the wiki link above and scroll down to “dynamic access”.
But you’ll need to use a variable structure as shown above, and not use it on the main parent of the structure.

1 Like

I see! Thank you!! :blush:

I figured it out!


Before


After


So each ‘mark’ object has a object variable. (stage number)
mark11 ~ object.Variable=11
mark12 ~ object.Variable=12
mark13 ~ object.Variable=13
etc.

And I replaced the index number in global variable with object variables.
Also all the objects (mark11, mark12, mark13 etc.) are in the object group ‘mark’

It’s complicated to explain but it works haha

2 Likes