Dynamic access to the children

Unfortunately, after days of reading Wiki, Forum and examples I have not found the solution.
I need to be able to assign a value to 20 variables children, that is to the variables Alfa.Beta1, Alfa.Beta2, Alfa.Beta3… 4… 5… 6 etc.
In order not to write the code every time 20 times, I would need a dynamic children variable, like in the Wiki example.
I recreated it, but it doesn’t work …

i can recommend This Topic

it helped me to create this:

that beeing said, i cannot see the problem with your events.
Maybe you should try a variable instead of a text variable.
cambia la Variable di scena alfa[“beta”+ToString(Variable(numero))] impostato su 250


thanks Barra, I’ll try tonight

a small step forward, but I just can’t understand. Now create the child variable by adding the next number, but it does it only the first time (for number 5 → base5) … then when I increase it it doesn’t create them anymore (…no creates base6 and base7).
In any case, however, it does not assign the indicated text to “base5”: it remains empty.
Strange that it creates “base5”, but not “base6” which is the same command.


I wrote the name of the child variable “base” by mistake, but it is actually “beta”

why are you using text, when you store numbers?
its more efficient to work with numbers and when you need the number in text use tostring then.

i just tested it, and the problem is the “beta”+
i am surprised that “sting”+ does not work, but a sting variable does.

if you can scip it you can easely get alfa.1 alfa.2 etc.
if you need the word beta in it it works if you have a variablesting with beta in it.

no strings in the screenshot, but i tested both, strings or numbers work.
i recommend not using strings

e: further testing resulted in a missing ()
so it should look like this:

1 Like

Strings or numbers don’t matter.

I’ve highlighted your problem. You’re setting a value to the value of your variables (yes, that’s not a typo). You need to set the value to the variable. Get rid of the VariableString as underlined (plus the parenthesis associated with it).

Also, you can just use VariableString(numero) instead of ToString(Variable(numero)). GDevelop casts it from a number to a string for you.

1 Like

:battere le mani::battere le mani::battere le mani::battere le mani:
thanks Barra and thanks MrMen, now it works.

na bro, its taglio not barra :slight_smile:
edit, no, if wikipedia is right it would be “Lacerazione”

it matters when it comes to performance, numbers are way faster.

I don’t understand. How is converting a number to a string faster than just straight out using the string?

i referd to the stored “values”.
storing and working with numbers as text, especially of many different variables is slow.

as for variable defenition ToString() or variableString(), i would assume they are equally fast, since both do essentially the same thing.

Oooh, that piqued my curiosity, because on the surface they appear to do the same thing. I ran a test (events shown below), and ToString() was about 15-20% slower than VariableString(). However, we’re talking close to 10000000 ToString() and VariableString() checks per second, so the difference for one conversion is nothing to write home about.



1 Like

thanks for testing that. Its good to know, even if it isnt much, but i can think of scenarios where this could come in handy. every little bit helps.

1 Like

For completeness of the discussion. For those who also need to use the children of the the children of the of the variables, can use this system. I have used global variables, but scene variables can also be used.