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

Grid 0, index out of bounds writing [-1,0] - size is [1,8] Compile Error

Hi GMC,
This is my first thread so I hope this works!;)

I am working on a survival game and am currently working on the inventory and crafting system. However I noticed that I seem to be getting this in my output window:

Grid 0, index out of bounds writing [-1,0] - size is [1,8]
Grid 0, index out of bounds writing [-1,1] - size is [1,8]
Grid 0, index out of bounds writing [-1,2] - size is [1,8]
Grid 0, index out of bounds writing [-1,3] - size is [1,8]
Grid 0, index out of bounds writing [-1,4] - size is [1,8]
Grid 0, index out of bounds writing [-1,5] - size is [1,8]
Grid 0, index out of bounds writing [-1,6] - size is [1,8]
Grid 0, index out of bounds writing [-1,7] - size is [1,8]
Grid 0, index out of bounds writing [-1,0] - size is [2,8]
Grid 0, index out of bounds writing [-1,1] - size is [2,8]
Grid 0, index out of bounds writing [-1,2] - size is [2,8]
Grid 0, index out of bounds writing [-1,3] - size is [2,8]
Grid 0, index out of bounds writing [-1,4] - size is [2,8]
Grid 0, index out of bounds writing [-1,5] - size is [2,8]
Grid 0, index out of bounds writing [-1,6] - size is [2,8]
Grid 0, index out of bounds writing [-1,7] - size is [2,8]
Grid 1, index out of bounds writing [0,15] - size is [1,15]
Grid 1, index out of bounds writing [1,15] - size is [2,15]
Grid 2, index out of bounds writing [-1,0] - size is [1,4]
Grid 2, index out of bounds writing [-1,1] - size is [1,4]
Grid 2, index out of bounds writing [-1,2] - size is [1,4]
Grid 2, index out of bounds writing [-1,3] - size is [1,4]

I have mucked around with it for a few hours now and I can seem to work out how to fix it. I have several similar scripts for initiating things such as items and recipes. I think the problem may be in the for loops but i can't work out what it is:

/// @description creates a new item and adds it to the itemData grid
/// @param name
/// @param description
/// @param holdSprite
/// @param dropSprite
/// @param invSprite
/// @param stackLimit
/// @param type
/// @param durability
/// @param effect
/// @param knockback
/// @param minedmg
/// @param chopdmg
/// @param attackdmg
/// @param clip
/// @param ammoSprite
/// @param ammoSpeed

//variables
var i, stats;
for (i=0; i<stat.allStats; i +=1)
{
stats = argument;
}
//add the items name to itemList and resizes the itemData grid
ds_list_add(global.itemList,stats[stat.name]);
var iid;
iid = ds_list_size(global.itemList)-1;
ds_grid_resize(global.itemData,ds_list_size(global.itemList),stat.allStats-1);
//input all arguments into the itemData grid
for (i=0; i<stat.allStats; i+=1)
{
ds_grid_set(global.itemData,iid,i,stats);
}

*stat.allstats is an enumerator.
Any help is very much appreciated and thanks in advance!:)
 

TsukaYuriko

☄️
Forum Staff
Moderator
First, let's examine what the messages mean to ensure we're on the same page here. There are two types of messages present.
Grid 0, index out of bounds writing [-1,0] - size is [1,8]
Note the "-1" - you're attempting to write to a negative index in the first dimension, which can not exist under any circumstances.

Grid 1, index out of bounds writing [0,15] - size is [1,15]
This one is a bit different. You're no longer writing to a negative index, but you're writing to element 15 in the second dimension. Note that the grid's size in the second dimension is 15, so there are 15 elements, starting from 0 and ending at 14. Therefore, there is no element at index 15 (which is the 16th starting from 0).

Unless you're certain that the code you posted is responsible for these, I suggest using the debugger and breakpoints to step through your code bit by bit to figure out which lines of code are generating these warnings.
 
First, let's examine what the messages mean to ensure we're on the same page here. There are two types of messages present.

Note the "-1" - you're attempting to write to a negative index in the first dimension, which can not exist under any circumstances.


This one is a bit different. You're no longer writing to a negative index, but you're writing to element 15 in the second dimension. Note that the grid's size in the second dimension is 15, so there are 15 elements, starting from 0 and ending at 14. Therefore, there is no element at index 15 (which is the 16th starting from 0).

Unless you're certain that the code you posted is responsible for these, I suggest using the debugger and breakpoints to step through your code bit by bit to figure out which lines of code are generating these warnings.
Thanks for the quick reply. I am aware that DSs start from 0 hence why i took 1 off the iid and ds_grid_resize.
I am pretty certain this is the code as i had another script which was exactly the same but different variables and when i took it out some of these errors left too.
 
Follow what TsukaYuriko said and use the debugger.
I managed to fix the issue. What was happening was the grid was being resized too small and the other issue was an extra function was inputing a string into another function that required a number
Thanks for pointing me in the right direction! I'd never used the new debugger before! It helped alot!
 
Top