Arrays can be very useful. You can save a list of say characters or locations or enemies. You can create an array with the names of objects and then randomly choose 1 and remove it. That way, you can create random enemies or power-ups that don’t repeat.
Arrays can be a list of numbers, strings or booleans but they can also be an array of structures. So, you could have a list of say characters with their hp, country, health, speed or any other characteristics. You could also create a lists of questions and answers for a quiz app. Then either go through the questions sequentially or randomly.
The advantages is that the same code can be used. You just change the index.
You can’t save an array directly to storage. You need to save the array as a string in the Json format. You then load the string and convert it to an array. There are examples and if someone hasn’t shared them. They will soon.
The array tools extension is extremely helpful. It allows you to sort, shuffle and do things like split the array. The split function allows you to take a string of text with the items seperated by say commas and split it into an array. It simplifies creating arrays. There’s also a search function.
Variables can be simple or complex. You can have an array of numbers or structure or structures with arrays or any other combination. The fewer levels the better though. It can get confusing.
Elements or indexes of arrays need to be the same type. Otherwise, the for each child wouldn’t know what to expect. If the first item is a number then they all need to be numbers. You can create an array of structures which contain numbers, strings or booleans but the structure children need to be identical for each item.
It’s a bit confusing because every programing language has their own syntax. Gdevelop tends to call the items in an array children just like in structures. I’m used to the terms indexes and elements.
Some functionality of arrays can be done with the new save system like saving objects or even saving the array itself.
Arrays are accessed similarly to structures using brackets. The difference being arrays use numbers while structures use strings or text.
Player[0] vs Player.Zero or Player[“0”]
An array of structures could be
Player[0].Name
Player[0].ID
You can also have multiple arrays or arrays of arrays for things like grids with columns and rows or X and Y
Grid[X][Y]
Grid[X][Y].Enabled
Grid[X][Y].Selected
Just like a structure, if you try to read an index that doesn’t exist then GD will create it. Not just that index but any missing previous indexes. So, if you try to read or even purposely create index 15 when there was only 5, GD will create the other 10. You can’t skip index numbers like structures. When in doubt, use the condition to count the children first.