First you need to make an array, which is any variable followed by
, such as
float. Then define the size of the array, let’s go with 8.
Next we need to make a for loop, which will loop through the body multiple times until it reaches the end. Let’s put it after a start event and make it end after 8 loops. Alternatively, you could get the length of the array and then plug that into the for loop, but currently there is a bug that will cause the for loop to not stop if it’s end is set to a variable.
To set variables within the array, we need a
set node. This node needs to know what array we are writing to, so use get variable to give it the array. Then plug in the index from the for loop, which will be whatever number the for loop is on. The first time it loops it will be 0, the second time 1, etc. until it is finished. Plugging that number into the array means you will be able to set the value of the array at that location.
In order to have something to fill the array with, I’m just going to make a random 0-100 range like so
And just to make sure it’s all working, let’s make a couple debug logs to see what it puts into each entry.
And after putting this on an object and pressing play, let’s see what it does
Perfect! Now let’s see how we can retrieve some of those numbers later. All we need is the
Float Get node, where we plug in the Array, choose which index to retrieve from, and print it to a debug log. You could also use another for loop to retrieve the entire array all at once.