How do I store item's the player has picked up?

jackapap

Member
Hi all,
I have been working on a platformer roguelike game and I need help figuring out how to display items the player has picked up.
An example is,
the player unlocks a chest and an item drops out, the player picks up that item when the collision mask meet, then (I want the item to be transparently displayed somewhere on the screen).
I am thinking I need an array for this, but I'm not sure ( I am fairly new to game maker) and how would I go about to do this if someone can give me pointers or even show me the code necessary to accomplish this, it would be much appreciated.
thanks,
 

jackapap

Member
Honestly, just Google "gamemaker player inventory" and there are plenty of tutorials showing you exactly how to do it. Probably best you try and apply a system using one of those, then you come back with your code and ask if you are having issues with it.

Also Yoyo even have an official tutorial on it - https://www.yoyogames.com/en/blog/coffee-break-tutorials-simple-inventory-gml
thanks for the help!
I checked out that link you sent and I refitted the code to act how I wanted it, and it's working perfectly.
one little issue that is bugging me is that I want the text size to be smaller when displaying how much of one item you have, but it changes all the text everywhere to that font size. I tried moving the location of the draw_set_font but that didn't fix it.

I don't believe it's clashing with anything although I could be wrong, I suspect that I just need to set it so it just draws for the items specific text.
help with this strange issue would be welcomed!
draw GUI:

//items
// had the draw_set_font here and didn't work
var _xx = camera_get_view_width(cam) -630;
var _yy = camera_get_view_height(cam) + 70;


for(var i = 0; i < 5; i += 1)
{
if !(item_array[i, item_type] == item_none)
{
draw_sprite(item_array[i, item_sprite], 0, _xx, _yy);
// had the draw_set_font here and didn't work
draw_text(_xx, _yy + 5, + string(item_array[i, item_amount]));
}
_xx += 40;
}
 

Slyddar

Member
one little issue that is bugging me is that I want the text size to be smaller when displaying how much of one item you have,
As I'm sure you know, once the the font is set, all text will use that font until you change it. So if you want it to be different for one loop, you need to set it to the right font, and after the draw event, change it back to the default font for the rest of the loop. Essentially you would need 2 if checks in the loop checking for the different condition, one at the start to set the different font, and at the end to reset.
 

jackapap

Member
As I'm sure you know, once the the font is set, all text will use that font until you change it. So if you want it to be different for one loop, you need to set it to the right font, and after the draw event, change it back to the default font for the rest of the loop. Essentially you would need 2 if checks in the loop checking for the different condition, one at the start to set the different font, and at the end to reset.
alrighty that fixed it,
thank you for the help!
 

Olivebates

Member
I'd do something like this

GML:
// Create master list of items
var itemID = 0;
items[itemID, 0] = "iron sword";      // Item name
items[itemID, 1] = 32;                // Damage
items[itemID, 2] = 52;                // Durability

itemID = 1;
items[itemID, 0] = "Wool";
items[itemID, 1] = 0;
items[itemID, 2] = 3;

itemID = 2;
items[itemID, 0] = "diamond armor";
items[itemID, 1] = 0;
items[itemID, 2] = 108;

itemID = 3;
items[itemID, 0] = "Table";
items[itemID, 1] = 0;
items[itemID, 2] = 24;

// Create player inventory
playerInventory = ds_list_create();

// Add two swords, one wool and one table to players inventory
ds_list_add(playerInventory, 0, 0, 1, 3);
When you want to draw the player inventory, just loop through playerInventory and look up the items in the master list.

Edit: I would make a function that "adds an item to the master list", so you don't have so much repeated code.
 
Last edited:
Top