• 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!

GML Check if in array

Z

zendraw

Guest
is there a better way to chech if im in an array?
GML:
if (((xm-1)>=0) && ((ym-1)>=0)) {global.tile[xm-1, ym-1].markmove=1};
 

FrostyCat

Redemption Seeker
You can hide the checking logic behind a script, but that's about it until we get exception handling.
GML:
///@func array2_get_failsafe(arr, xx, yy, defval)
///@param arr
///@param xx
///@param yy
///@param defval
if (argument1 >= 0 && argument2 >= 0 && argument1 < array_height_2d(argument0) && argument2 < argument_length_2d(argument0, argument1)) {
    return argument0[argument1, argument2];
}
return argument3;
GML:
with (array2_get_failsafe(global.tile, xm-1, ym-1, noone)) {
    markmove = 1;
}
 
Top