• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker what does a out of bound array return?

S

Shadowblitz16

Guest
does anybody know what a out of bounds array returns?
I'm asking this because I need to check if the index exists.
 

FrostyCat

Redemption Seeker
It doesn't return anything, it gives you a "variable index out of range" error.

Use the array dimension functions to see ahead of time whether an index is in-range.
Code:
// 1D
if (0 <= i && i < array_length_1d(array1d)) {
  //array1d[i] exists
}

// 2D
if (0 <= i && i < array_height_2d(array2d) && 0 <= j && j < array_length_2d(array2d, i)) {
  //array2d[i, j] exists
}
 
Top