Iterating Child Variables

Is it possible to use a while loop to create a loop that keeps on creating child variables for a structure?
Like name the child variables 1, 2, 3, ect.
I know it is an infinite loop but I will be adding conditions so that it doesn’t crash.

Of couse, “very possible” :laughing:

I didn’t test it, but should work:

set Variable(i) = 0 While (Condition) Variable(yourStruct.Variable(i).ValueA) = valueA Variable(yourStruct.Variable(i).ValueB) = valueB Variable(yourStruct.Variable(i).ValueC) = valueC do Variable(i) += 1 (actions to make Condition become "false")

The variable “i” is a counter to change the struct item every iteration.

It will create a structure like this:
—yourStruct
------1
---------ValueA
---------ValueB
---------ValueC
------2
---------ValueA
---------ValueB
---------ValueC

------n
---------ValueA
---------ValueB
---------ValueC

Thanks for the expert reply.
I’ll test it now.

Ran in to trouble almost right away.
Don’t forget that you can’t use the Variable syntax (Variable(variablename)) when you are setting a variable to a value.
At least I don’t think you can. Any help on that?
Or do I need to code an extra C++ file?
Also if I do need to code C++, you’ll have to tell me how because I only have experience with Python and Java.

I think Lizard 13 answer was king of pseudo code, at least it’s not the right syntax :slight_smile:
But you can use the brackets notation :

yourStruct[ToString(Variable(i))].ValueA

This syntax can be used anywhere a variable is required:

Set yourStruct[ToString(Variable(i))].ValueA to 0 Set variable Score to yourStruct["Player"+ToString(Variable(PlayerIndex))] to 100

More information at the end of this page: :slight_smile:
wiki.compilgames.net/doku.ph … evariables

It would be nice to add detailed information about using structure variables to this page with examples, or for beginners it is too short and not very usefull.
I liked the example of Lizard13 with Primitive drawing where he uses structure variables. I still use it like reference when I need to work with structures:
viewtopic.php?f=19&t=5544
File: RectangleDraw.gdg

Yeah, it’s a pseudocode but the wrong syntax was unintentional :blush:
I didn’t check this, and I think usually use this bad syntax, then I realize it doesn’t work and correct it :stuck_out_tongue:

Ahhhhh thanks.
I’ll be testing tomorrow because I don’t have time :smiley:.
Thanks!

Nope, tested and the structure system doesn’t seem to work for me. However, you game did give me an idea. I can simply save the child variables in invisible objects :smiley:

You can upload your game (with images better) here to check the error, otherway you’ll never know why it doesn’t work :slight_smile: