I know you can use square brackets [0] to address child by index
So does [“ccc”] address child by name?
I never saw it and actually i never did wonder how to address child by name
My confusion comes from putting name inside double quotes
So is it addressing child ccc which is child of aaa structure?
And this is how you address child vars by name?
In that example there was no need for the brackets and quotes. It works but it’s not needed.
aaa[“ccc”] is the same as aaa.ccc
With arrays you use
variableName[#] the # is the child or index
With structures you can use
variablesName.child or variableName[string]
When you use the brackets it’s for creating the child name dynamically. You wouldn’t usually use just text in quotes. You would add something after the quotes or instead of the quotes like another string variable name. Something that can be changed at runtime.
aaa.ccc or aaa[“ccc”]
Set temp to “ccc”
aaa[temp] (no quotes means variable)
Set string variable temp to “11”
aaa[“ccc” + temp]
(this would be the same as aaa.ccc11)
You can use a variable or an expression or any combination added together with a plus symbol. If it returns a number you would need to convert it to a string with ToString(#).
Number variable Temp=11
aaa[“ccc” + ToString(temp)
(this would be the same as aaa.ccc11)
You can use multiple dynamic child names. You can’t make dynamic variable names only the children. If you add brackets then you don’t need the period but if you use a child name not in brackets then you would use a period. It can get confusing. You wouldn’t normally use too many children. You would also use short but descriptive variable and child names.
So bottom line anything inside of quotes and so not only but most likely reason i would use it is if i want add something to text
So for example i have Dungeon.Level and now i could go with
Dungeon.Level[Lava]
But if i would want stick to it i would go with
Dungeon.Level[“Lava”+Red]
Or
Dungeon.Level[“Lava”+Blue]
Where more sense of practical usage would be
Dungeon.Level[“Lava”+SomeVariable]
So i could dynamically change what is after Lava instead of pre making events for all possible combination
Yes. In this case Red would be a variable because it’s not in quotes.
Dungeon.Level[“Lava”+Red]
You could use
Dungeon.Level[“Lava” + color]
Where color would be a variable.
Dungeon.Level.Lava[NewSprite.color]
Where color would be an object variable.
Which could access
Dungeon.Level.Lava.red
Dungeon.Level.Lava.gold
The nice thing is the dynamic name can come from any string. A scene, global or object variable, an animation name, a scene name or anything that ends up being a string.