0
\$\begingroup\$

The code is this:

if is_undefined(A_SA[V_X,V_Y])=false and A_SA[V_X,V_Y]=0
{
//actions from the "if" statement
}

The error message is this:

Push :: Execution Error - Variable Index [0,10] out of range [10,10] - -1.A_SA(100006,10)
 at gml_Object_objt_Canvas_StepNormalEvent_2 (line 25) -         if is_undefined(A_SA[V_X,V_Y])=false and A_SA[V_X,V_Y]=0

Why is this happening and how can I stop game-maker from trying to check the value of a variable outside of an array?

\$\endgroup\$
0
\$\begingroup\$

is_undefined can be used for ds_map and doesn't work with arrays.

Initialize array by values, which won't cross with values you will use later. For example, if you will use values 0 and greater, then you can initialize by negative value -1.

If you will use any values in full available range then you need create other array with same size where each cell will show, is initialized same cell of other array, or not.

Or you can use ds_map with is_undefined, where index will be used as key.

About Variable Index [0,10] out of range [10,10]. If array size is 10, then maximum index is 9.

\$\endgroup\$
0
\$\begingroup\$

You can also check if each element is a null pointer, for an array is a list of locations that point to space in data, by default all of them are set to a null value that can be accessed with pointer_null. in my game I use it to remember a list of 4 specific instances and access their states, like this:

if ( playerlist[0] != pointer_null && instance_exists( playerlist[0] ) )
{
    if playerlist[0] .state == state_dead { global.player1 = false; }
}
else
{ global.player1 = false; }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.