• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Array out of range

clee2005

Member
Hey gang!

I'm getting this error randomly from some users and am trying to figure out how this might be happening :

Code:
Push :: Execution Error - Variable Index [0,2] out of range [5,0] - -1.mask(100160,2)
My understanding is that it's saying my array var named mask is attempting to be accessed at [0,2] which is out of range as it is allocated to be [5,0]. The thing is that I'm only allocating that array in one place in a create event and it's allocated as mask[4,2] = 0;

So I'm thinking that I do not understand the error properly, or perhaps there is some kind of out of memory thing happening on the devices (Android devices - Google Play) that is trashing the array? It's just holding integers.

Any ideas or advice?

Thanks,
Chris
 

kupo15

Member
My understanding is that it's saying my array var named mask is attempting to be accessed at [0,2] which is out of range as it is allocated to be [5,0]. The thing is that I'm only allocating that array in one place in a create event and it's allocated as mask[4,2] = 0;
This isn't a grid by chance? When else are you accessing the grid/array even to reference it? Somewhere in your code, you are accidentally setting the grid/array to a height of 0. Any place you are accidentally setting the variable name only to something?

Maybe you can open up the debug console and replicate the steps, it might show you more information about when exactly this is happening
 

Simon Gust

Member
A [4, 2] array created like this has a height of 0 in any other position than 4. You may use a for loop to initialise the height to 2 for every index in its length.
 

clee2005

Member
A [4, 2] array created like this has a height of 0 in any other position than 4. You may use a for loop to initialise the height to 2 for every index in its length.
@Simon Gust Really? I would never have thought that to be the case, but maybe that's what's happening here. The error is happening in the draw event perhaps before the array is properly populated. What doesn't make sense, is that it is populated later in the same create event where it was declared mask[4,2] = 0. There are a lot of things happening in this create event though as it's the game controller. I wouldn't have expected the draw event to fire before the create event was completed? I guess that's possible?
 

clee2005

Member
This isn't a grid by chance? When else are you accessing the grid/array even to reference it? Somewhere in your code, you are accidentally setting the grid/array to a height of 0. Any place you are accidentally setting the variable name only to something?

Maybe you can open up the debug console and replicate the steps, it might show you more information about when exactly this is happening
Thanks @kupo15 It's an array not a grid. And no I'm not setting it anywhere else in my code. It's VERY random and not reproducible, which is why I'm reaching out for thoughts since I can't debug it conventionally.
 

Posh Indie

That Guy
@Simon Gust Really? I would never have thought that to be the case, but maybe that's what's happening here. The error is happening in the draw event perhaps before the array is properly populated. What doesn't make sense, is that it is populated later in the same create event where it was declared mask[4,2] = 0. There are a lot of things happening in this create event though as it's the game controller. I wouldn't have expected the draw event to fire before the create event was completed? I guess that's possible?
You are missing the point of what @Simon Gust said. Initializing a 2D array simply by setting a single value does not work like you are assuming it does (Unless you are using a 2D array as a 1D array, maybe... but that would be a pointless practice, and based on what you have provided, this is obviously not the case). You would (at the very least) need to initialize for the height of each positional width.

If your Users are experiencing it "randomly", I would wonder if it is being drawn in an area that Users do not have to actually go to (Some just may not be using the feature/triggering the draw call). This is an assumption because we are left with little information to go by (Index is out of range, some people are experiencing it).

This does not mean the Draw event ran before the Create event (That is an incorrect assumption and is probably what is making your debugging/fixing of the code tougher than it has to be). It having the error in the Draw event is because it was never "properly populated" in the first place and a bad index is first being accessed in the Draw event.
 
Last edited:

clee2005

Member
Thanks @Posh Indie . I did catch what @Simon Gust was saying. What I was saying is that the only way that could be a problem (unpopulated or initialized array) is if the draw event fired before the create event had completed entirely, since the array is fully populated ..... and there it is. I just realized what's happening. The array is populated with meta data from the level and there is 1 level out of 600 that I built which is missing a required piece of data and so the array doesn't populate properly... had I iterated to initialize the array as @Simon Gust pointed out then this wouldn't have happened.

Thank guys for your help!
 
Top