Arrays?

Can arrays be implemented in GD? It seems like quite an easy and fundamental thing to exist in a game development environment. Is there some reason why it is not already existing? :confused:

The GD “implementation” of arrays are structure variables, if you call the items “0”,“1”,
,“n”

I think it would be nice to add expressions and functions as: size of an array, sort and array by value, reverse array, slice.

but don’t worry, all this can be achieved with some extra code :wink:

Can you show some examples for it? :wink:

Here is my example of a simple array:
Structure variable Array with childs 0-9: Array.0-Array.9

Events:

Result:

array_result.png

Yeah, of course :slight_smile:

I use an extra item (e.g. size) to follow the array size, for example:

Array ....size = 2 ....0 = Value_0 ....1 = Value_1
Then I can use: Array.size (It looks good :smiley:), for example:

No condition --------- Do = 0 to variable "counter" Repeat (Array.size - 1) times: ........No condition --------- Do +1 to variable Array[VariableString(counter)] ........No condition --------- Do +1 to variable "counter"
It code will add 1 to every item in the array, without create new items accidentally. You just have to increase the size when add items.

To get modified arrays, my idea was copy the array values in another array, modifying its indices:

I made an example today:
[url]Besoin d'une Ă©quipe pour votre projet de jeu?]
It sorts a list by the value “Points” instead the default “ABC” of the name, as you can see, you can use any value from the array to sort it, and the functionality “High-to-Low value sorted” can be easily modified in the condition “Value_of_an_item >= Value_of_the_other_items” :wink:

I think it’s easier than sort the array by value
 for example:
Item[0] ==> Item[Array.size - 1]
item[1] ==> Item[Array.size - 2]


Item[Array.size - 1] ==> Item[Array.size -1 - (Array.size -1)] = 0
So:

No condition --------- Do = 0 to variable "counter" Repeat (Array.size - 1) times: ........No condition --------- Do = Array[ToString(Variable(Array.size)-1-Variable(counter))] to variable CopyArray[VariableString(counter)] ........No condition --------- Do +1 to variable "counter"
Or something like that :smiley:

Just have to define the initial value of a counter, and check final value, and your custom condition.
For example, I want to add 2 to every array item, from the third to the tenth items, two-by-two (index even numbers):

No condition --------- Do = 2 to variable "counter" #The second index is the third item (if you start naming from 0) Repeat (10-2 = 8) times: #9th index (tenth value) included ........If Variable(counter) % 2 = 0 --------- Do + 2 to variable Array[VariableString(counter)] ........No condition --------- Do +1 to variable "counter"
Or don’t check the Counter%2 = 0, but add +2 to the Counter in every iteration :slight_smile:

Thanks! :slight_smile: Will use your examples as a reference while working with arrays (still think that in Python, for example, they are easier to use, especially you don’t need to use ‘Variable’, ‘ToString’ or ‘VariableString’ expressions so often which makes the array expressions so long, error prone and intimidating for beginners).

1 Like