How to access Structures Children With a Name (SOLVED)

im trying to add to the name of a variable how do I get this to work

I cannot figure out why its not working I SWEAR IT WORKED A FEW MONTHS AGO

1 Like

You would need to show a code example. Generally, variable names are not and never were something that exists as a value, only the value they refer to can be used directly.

What you can do, if you have two variables, say DialogueId1 and DialogueId2 which are set to the values 1 and 2 respectively, is using the dynamic accessor ([]), which allows to get a child variable using the result of an expression as child name: DIALOGUENameLeft[DialogueId1 + DialogueId2]

Okay so I found out how to fix it???

STRUCTURE *global

DIALOGUETEXTADDER *Global
image

at beginning of scene my json files which contain all dialogue are loaded in
they auto add to children which is awesome :smiley:

If i chose arrays this would’ve been way simpler but whatever I’m already here lol

by doing

DIALOGUE2[ToString(DIALOGUETEXTADDER)]
image
I got it to load in game :smiley:

I will have to change a little bit rn but it should be working

THANK YOU :smiley:
I have no idea why I had to put ToString but whatever lol it works

Structures use child names as a string that contains letters, numbers or a few special characters. The first character of the child name shouldn’t/can’t be a number. The first character is almost always a letter except in a few rare exceptions.

Arrays use indexes which are sequentially numbered started at index zero.

Structure
Fruit.Apple
Fruit[“Apple”]

If the variable LastLevel was a string
Game[“Level” + LastLevel]

If the variable LastLevel was a number
Game[“Level” + ToString(LastLevel)]

The child name in the brackets can be anything that returns a string or can be converted to one.

Array
Fruit[0]

The same applies to arrays except the index must be a number or anything that returns a number.

There are times when you may need to convert a number ToString() or a number stored as a string ToNumber()

If the required type is wrong or doesn’t exist then GDevelop will try to prevent a crash by returning zero or the default value. In many cases, trying to read certain variables will cause GDevelop to create that variable or index.

Dude your litteraly the only reason I even kept with gdevelop for so long

You helped me with something so simple in hindsight :smiley:

Dude im pretty sure u made a demo or smtn for me to?

also thanks for your explanation :smiley:

1 Like