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?
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
Can you show some examples for it?
Here is my example of a simple array:
Structure variable Array with childs 0-9: Array.0-Array.9
Events:
Result:
Yeah, of course
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 ), 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â
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
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
Thanks! 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).