Ds_Grid Help

I don't know a whole lot about ds grids but found this awesome inventory system that uses ds grids, well to remove items from the inventory you run this script.

[
//If there's only 1 item in the inventory
if(ds_grid_height(playerInventory) == 1) { //Only 1 item in inventory
if(ds_grid_get(playerInventory, 1, 0) > 1) //If there's more than 1 in the inventory, just subtract it by 1
ds_grid_set(playerInventory, 1, 0, (ds_grid_get(playerInventory, 1, 0) - 1));
else {
for(i = 0; i < ds_grid_width(playerInventory); ++i) {
ds_grid_set(playerInventory, i, 0, 0);
}
}
}
//Item is anywhere else (including first item in a list)
else {
//First check to see if amount if greater than 1
if(ds_grid_get(playerInventory, 1, itemSelected) > 1)
ds_grid_set(playerInventory, 1, itemSelected, ds_grid_get(playerInventory, 1, itemSelected) - 1);
else { //Then shift every item down 1
var currentRow = itemSelected + 1;
var rowToRemove = itemSelected;
for(i = rowToRemove; i < ds_grid_height(playerInventory) - 1; ++i) {
ds_grid_set_grid_region(playerInventory, playerInventory, 0, currentRow, 5, currentRow, 0, i)
currentRow += 1;
}
//And resize the grid to delete the last item in it
ds_grid_resize(playerInventory, 5, ds_grid_height(playerInventory) - 1);
//Make sure the selection isn't on the item that was just deleted
if(scrolledAmount > 0)
--scrolledAmount;
if(itemSelected > 0)
--itemSelected;
}
}
]



Whenever I had a single type of item in my inventory and went to delete it, it gives me this

Iv tested it out and it only happens when I only have a singular type of that item

FATAL ERROR in
action number 1
of Draw Event
for object obj_InventoryGUI:

draw_sprite argument 1 incorrect type (undefined) expecting a Number (YYGI32)
at gml_Object_obj_InventoryGUI_DrawEvent_1 (line 23) - draw_sprite(ds_grid_get(myItems, j, i + scrolledAmount), 0, bbox_left + 40, itemTopStart + (i * 32) + 16+1.5);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_InventoryGUI_DrawEvent_1 (line 23)
 

Nidoking

Member
There was just a post like this a few weeks ago. The problem is that there's no grid element at coordinates j, i + scrolled amount, so it's returning undefined. As for reading what you've posted, it would help to put it in a CODE block.
 
Top