SquiggleyPete
Member
Hello. Using GMS Pro vers. 1.4.1757.
I posted not long ago about help setting up arrays to define my inventory. Thanks to community responses, I think I have that under control; now what I'm having trouble with is drawing the inventory correctly. Currently, when I pick up an item, it draws it in every slot of the inventory rather than just one.
Here is the create event for the inventory:
The last two lines are for testing purposes, in order to see if it will display the correct item (2) and quantity (5) in the correct box (6).
Now the draw event code:
The problem I'm seeing is that the coffee sprite and quantity are displayed in EVERY box, rather than just box 6. So the draw_sprite and draw_text functions are running for every value of i, but shouldn't only one of those values of i (6) be greater than -1?
Any help appreciated.
I posted not long ago about help setting up arrays to define my inventory. Thanks to community responses, I think I have that under control; now what I'm having trouble with is drawing the inventory correctly. Currently, when I pick up an item, it draws it in every slot of the inventory rather than just one.
Here is the create event for the inventory:
Code:
globalvar show_inv; //whether to display inventory
show_inv = false;
maxslots = 20;
//setting item ID and item count
for (i = 0; i < maxslots; i ++) //slot count
{
global.inventory[i,0] = -1 // id of items in all slots are -1, no item
global.inventory[i,2] = 0 //count of items in all slots set to 0
coordx[i] = 0;
coordy[i] = 0;
}
space = 32;
rows = 4;
columns = 5;
//dimensions of black display box
x1 = view_xview[0]+80;
x2 = x1+240;
y1 = view_yview[0]+32;
y2 = y1 + 160;
global.inventory[6,0] = 2; //set inventory 6,0 to item id 2 (coffee)
global.inventory[6,2] = 5; // set quantity of item to 5
Now the draw event code:
Code:
for (xx = 0; xx < columns; xx++)
for (yy = 0; yy < rows; yy ++)
{
draw_sprite(spr_box_16x16, 0, x1+space+(xx*space), y1+space+(yy*space)) //draws empty boxes
for (i = 0; i < maxslots; i ++)
coordx[i] = x1+space+(xx*space);
coordy[i] = y1+space+(yy*space);
if global.inventory[i,0] > -1
{
draw_sprite(spr_items, global.inventory[i,0], coordx[i],coordy[i]);
draw_set_colour(c_white);
draw_text_transformed(coordx[i]+12,coordy[i]+13,string(global.inventory[i,2]), .5, .5, 0);
}
}
}
Any help appreciated.