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

Legacy GM [Solved] Variable Index [10,0] out of range [10,-1]

Hey everyone, I feel that I'm pretty experienced with arrays so when I seen this error I thought it would be a simple fix but I can't find the issue!
Here is my error:
Code:
Push :: Execution Error - Variable Index [10,0] out of range [10,-1] - -5._InventoryCraftS(100151,320000)
 at gml_Script_InventoryCraft (line 7) - if(_InventoryCraftS[t,v] = ds_map_find_value(_InventoryCraftList,v)) { } else { tBroke = 1 }
Here is the script where the error occurs:
Code:
///InventoryCraft()
tGotItem = 0 t=1 tBroke = 0

for(t=0;t<=array_height_2d(_InventoryCraftS);t+=1) {

for(v=0;v<=9;v+=1) {
if(_InventoryCraftS[t,v] = ds_map_find_value(_InventoryCraftList,v)) { } else { tBroke = 1 }
}

if(tBroke = 0) {
InventoryGiveItem(t,1)
for(z=1;z<=9;z+=1) {
ds_map_replace(_InventoryCraftList,z,0)
}
tGotItem = 1
}
}

if(tGotItem = 0) {
for(m=1;m<=9;m+=1) {
if(ds_map_find_value(_InventoryCraftList,m) != 0) { InventoryGiveItem(9,1) }
ds_map_replace(_InventoryCraftList,m,0)
}
}
So what this script is suppose to do is go through the array "_InventoryCraftS" and check if the map "_InventoryCraftList" values equal it. It is used to create a crafting menu sorta like Minecraft. It's kind of hard to explain so if you want more information then just ask. _InventoryCraftS is declared in this script:
Code:
///InventorySetCraft(Item ID, Slot: 1,2,3,4,5,6,7,8,9)
tID = argument0

_InventoryCraftS[tID,1] = argument1
_InventoryCraftS[tID,2] = argument2
_InventoryCraftS[tID,3] = argument3
_InventoryCraftS[tID,4] = argument4
_InventoryCraftS[tID,5] = argument5
_InventoryCraftS[tID,6] = argument6
_InventoryCraftS[tID,7] = argument7
_InventoryCraftS[tID,8] = argument8
_InventoryCraftS[tID,9] = argument9
_InventoryCraftList is a map that has 9 slots each one that will contain 0-9, so will _InventoryCraftS. I really don't know how else to explain it. If you need more info then please tell me. thanks!
 
C

CoderJoe

Guest
I always try to fix bugs like this with the debugger. Try to look at the value of your variables and make sure its not going past the array size
 
T

TimothyAllen

Guest
The last index of an array is 1 less than its length, or in this instance, 1 less than the height.
 
I

icuurd12b42

Guest
arrays also start at index 0, not 1. if your array is size 10 then entry 0 through 9 are valid
 
Top