DS accessor not being read as a number for sprite subimage

I reccently followed the heartbeast tutorial for creating an inventory system, in which he creates a ds-grid to store items, and then references it in a for loop in the draw event to display the correct item, with the value in the grid being a number that corresponds to a subimage of a sprite (this sprite holds all the items in the game). When i go to draw it, with the code below, I get the following error, also shown below:
//draw the inventory
for( ydraw = 0; ydraw < width; ydraw++;){
for(xdraw = 0; xdraw < height; xdraw++;){
var tx = 700+(xdraw*box_size);
var ty = 270+(ydraw*box_size);

draw_sprite(sItems,box[# xdraw,ydraw],tx,ty);
if(count[# xdraw, ydraw] > 0){
draw_text(tx,ty-8,count[# xdraw, ydraw]);

Can someone explain why the values in the ds grid arent able to be read as numbers that correspond to a sprite subimage?


Did you previously create your box ds_grid and populate it with all the image indexes? Essentially box[# xdraw,ydraw] is a reference at coordinate(xdraw,ydraw) inside your ds_grid which should hold a value, a value you need to put there yourself.
hey thanks for the reply, yeah i did create a grid and i did populate it with the indexes, added a couple items to it (sword is image index1,apple is 2, scroll is 3)
I think the values are in the grid, as shown below with the screen shot and code
draw_sprite(sItems,box[# 0,0],480,270);
draw_sprite(sItems,box[# 1,0],520,270);
draw_sprite(sItems,box[# 2,0],560,270);


The error says it's expecting a number but isn't getting one. Try clearing your grid after it's created before populating it with the image indexes: ds_grid_clear(box, 0);
Maybe your for loops are going into regions with non-numbers because you didn't clear it.

Edit: If you clear the grid with 0's and have an image at index 0 it'll be referencing image 0. So maybe clear with -1's, or draw a blank sprite at index 0.
just got it i had switched the height and width variables in the drawing for loops which was i guess referencing grid values that were outside what i had originally defined. Thansk for the help tho that defnitely got me looking in the right direction!


Oh right, didn't spot that, you have ydraw check with the width and xdraw check with the height. Should be the opposite. Those kinds of bugs are sometimes the toughest to find. We stare and stare at code and it looks like it makes sense but it's always small details like that. I've had bugs that I couldn't figure out for days, and it turned out to be stuff like this, in plain sight but the mind doesn't register it. Glad you found it