Simulating dynamic arrays with structure notation

In GDevelop you can use structure notation applied to an action to declare the child of a structure:

Do = 1 To Variable myStruct["myChildVar"]

NOTE: any argument passed between square brackets must be a string.
TIP: use the VariableString() function (instead of the Variable() function) to get the value of a variable expressed as a string.

You can also declare it dynamically:

Do = 1 To Variable myStruct[VariableString(myVar)]

And use almost the same syntax to dynamically access its value:

Do = Variable(myStruct[VariableString(myVar)]) To Variable myVar

NOTE: the syntax used in the “name field” (the field that holds the name of the variable) must be wrapped by the Variable() function when used in the “value field” (the field that holds the value of the variable).
EXAMPLE:

  • for the “name field”, when declared: myStruct[VariableString(myVar)]
  • for the “value field”, getting access to its value: Variable(myStruct[VariableString(myVar)])

So, you can simulate dynamic arrays (declared during an iteration for example):

Do = 1 To Variable myStruct[VariableString(myCounterVar)].myChildVar

And dynamically access its value:

Do = Variable(myStruct[VariableString(myCounterVar)].myChildVar) To Variable myVar

Or access the value of a specific element of the array (in this example, 5):

Do = Variable(myStruct["5"].myChildVar) To Variable myVar

You can even use double square brackets to simulate a 2D array:

Do = 1 To Variable myStruct[VariableString(counter1)][VariableString(counter2)].childVar

And dynamically access to its value with almost the same syntax (wrapped by the Variable() function):

Do = Variable(myStruct[VariableString(counter1)][VariableString(counter2)].childVar) To Variable myVar