Error When trying to remove remove an item from a grid

L

Logan Bevans

Guest
The Error Code is

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_smelteryGUI:

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

The Draw Event Of smelteryGUI//////////////////////////////////////////////////////

draw_self();
draw_set_colour(myColor);
//Draw the column names
//draw_text(bbox_left + textBorder+10, bbox_top + textBorder, "Image");
draw_text(bbox_left + 110, bbox_top + textBorder, "Smeltery");
//draw_text(bbox_left + 152, bbox_top + textBorder, "Amount");


itemLeftStart = bbox_left + 120;
itemTopStart = bbox_top + 48;
//textHeight = max(string_height(string(ds_grid_get(myItems, 0, 0))), sprite_get_height(sprArmor)); //Gets the height of the string EXPLAIN CASTING

for(i = 0; i < inventoryEndAt; ++i) {
for(j = 0; j < ds_grid_width(myItems); ++j) {
inventoryOnScreen = i; //Be able to track what value i is outside of the for loop
if(j == 0) //Draw the name in the right spot
draw_text(itemLeftStart-25, itemTopStart + (i * 32)+16, ds_grid_get(myItems, 0, i + scrolledAmount));
else if(j == 1) //Draw amount in the right spot
draw_text(itemLeftStart +35, itemTopStart + (i * 32)+16, ds_grid_get(myItems, 1, i + scrolledAmount));
else if(j == 3) //Draw sprite in the right spt
draw_sprite(ds_grid_get(myItems, j, i + scrolledAmount), 0, bbox_left + 23, itemTopStart + (i * 32));
}
}

//Show item selection by a rectangle
draw_rectangle(bbox_left + textBorder, itemTopStart + ((itemSelected - scrolledAmount)
* 32), bbox_right - textBorder, itemTopStart + ((itemSelected - scrolledAmount) * 32)
+ 32, true);
//Draw description of sprite
//draw_sprite(spr_ItemBox, 0, obj_InventoryGUI.x+238,obj_InventoryGUI.y+21);
//Draw the text inside of the description box. If it's empty, draw that message inside
//if(isEmpty)
//draw_text_ext(bbox_right + 50, room_height - sprite_get_yoffset(spr_ItemBox) - 100, emptyMessage, 32, sprite_get_width(spr_ItemBox) - textBorder);
//else
//draw_text_ext(bbox_right + 15, room_height - sprite_get_height(spr_ItemBox) + 15, ds_grid_get(myItems, 2, itemSelected), 32, sprite_get_width(spr_ItemBox) - textBorder);

//Draw scrollbar
if(ds_grid_height(myItems) > floor((sprite_height - (textBorder * 3)) / 32)) {
draw_sprite(spr_ScrollBar, 0, bbox_right, 20 + bbox_top + itemSelected * (sprite_height - textBorder) / ds_grid_height(myItems));
}


draw_text(x, y, string(smeltTimer));

STEP EVENT////////////////
///Smelting Process

if smeltTimer_Start = true {
smeltTimer -=1;
}

if smeltTimer = -1{
smeltTimer = 30;
}


if ds_grid_get(smelteryInventory, 0, itemSelected) = "Iron Ore" {
nameOfItem = "Iron Ingot";
spriteOfItem = spr_ironingot;
smeltTimer_Start = true;
if smeltTimer = 0{
smeltTimer_Start = false;
smeltTimer = 30;
//trashSmeltery();
addItem(smelteryInventory,nameOfItem,global.myItemAmount,global.myItemDescription,spriteOfItem,global.myItemScript);
trashSmeltery();
}
}
 

chamaeleon

Member
I guess the position in the grid indicated by ds_grid_get(myItems, j, i + scrolledAmount) does not actually contain a valid value (hence "undefined" in the error message). Perhaps you should debug your code to ensure that what you pull out is something you have previously set for that particular position, whatever i and j may be at the time of the error. Your loop indicates i goes from 0 to inventoryEndAt (not including), but then you add the scroll amount when getting the value. Have you actually stored anything at inventoryEndAt or further in the grid?
 
Top