[Fixed] Call a Variable by an other Variable

Hi,
What im trying to do here is to call a variable by his name with an other variable that contain the name of the variable. To explain easier
I have a scene variable with the parent variable “Text” and children variable “1” that contain “Welcome” and “2” for “Bye” So if I try to show how it look like, it would be like that

[code]Text

  • 1 : “Welcome”
  • 2 : “Bye”[/code]
    What im trying to do is to give to a text object the Text.1 variable and then Text.2 variable

A default way that is working is by doing like that : prntscr.com/ii8brq and it work.
What I want now is to change the text to the next one, each time I press space.
So what im trying to do is like increment a variable each time I press space by +1 (let call this variable ‘textNumber’)
And then call the the good children number like that: prntscr.com/ii8e2c
Problem is, it look like Gdevelop don’t like when we call a variable name by not a string directly…
Is there any way to fix this ? :frowning: Thanks

Yes, instead the fixed way:

Variable(ParentVariable.ChildName)

You can use dynamic strings (variable strings with quotes around) through the dynamic expression for variables:

Variable(ParentVariable["ChildName"])

So your action should be like:

Do = VariableString(Text[VariableString(textNumber)]) to the text of DialogueText

And if I want to stock “text” in an other variable like ‘DialoguePart’, so im using 2 variables
I tried many ways, non work :U

Do = VariableString([VariableString(DialoguePart)][VariableString(textNumber)]) to the text of DialogueText
Do = VariableString([VariableString(DialoguePart)]+[VariableString(textNumber)]) to the text of DialogueText
Do = VariableString(VariableString(DialoguePart)[VariableString(textNumber)]) to the text of DialogueText
Do = VariableString(VariableString(DialoguePart)+[VariableString(textNumber)]) to the text of DialogueText

?

You need a root variable, like this:

TextsRoot ....DialoguePart1 ........1 "welcome" ........2 "bye" ....DialoguePart2 ........1 "ok" ........2 "no" ....DialoguePart3 ........ ....
Then you can do it:

Do = VariableString(TextsRoot["DialoguePart" + VariableString(dialoguePartNumber)][VariableString(textNumber)]) to the text of DialogueText

You need a root variable to access childs dynamically… always :slight_smile:

You’re a god, honestly :ugeek:
Thanks a lot Lizard-13 <3