GameMaker best inventory system?

J

John Smillie

Guest
I'm looking for the best way to code an particular inventory system for my game. I want to be able to pick up an item in the game, or be given an item by an npc, then have the item disappear and for the sprite to be drawn in the inventory, which would be viewed by pressing a button. Then I want the items to be able to be taken from the inventory when the player reacts with various npcs in the game. Very simple, none of the items need to be used in any way, they just need to be received and be taken away. Anyone know what the best way to do this is, or is anyone able to point me towards the right tutorial?
Please ask if you need me to elaborate or show some code.
 

Psycho_666

Member
I'm so sorry, but I'm going to be that guy... You know, THAT guy...
There are like a billion tutorials on YouTube. I know, I have watched half of them when I made my RPG 5 years ago. Not to mention all the tutorials in the tutorial section of the forum...
Seriously, check out YouTube and the tutorial section here. So many inventory systems.
When I reach the items part of my game I will post my tutorial system on YouTube as well, so there will be another one...
 

3dgeminis

Member
You can use Arrays or data structures like Stacks, Queues, Lists, Maps, Priority Queues or Grids. Start whith 2d array.
 

Kealor

Member
If you don't know how to use data structures in GMS, i recommend learning, they are better optimized and easier to manage than arrays.

As for the best type of inventory, it depends on your games design. Do you want a categorized list like skyrim/most rpgs or a grid based slot system like minecraft?. For the former you'll want ds_maps and for the latter you will want ds_maps and ds_grids.

I can go into more detail if you want, but like Psycho said, there are hundreds of these guides on youtube.
 
T

trentallain

Guest
If you want the items taken away then I recommend using ds_lists because of the ds_list_delete function which removes the item and then shifts everything up.
 
I'm obviously biased a bit, but if it fits your design, I recomend my system which I have a tutorial for here: https://forum.yoyogames.com/index.php?threads/flexible-inventory-system.34884/ I use ds_grids with enumerators to name stuff. It has a lot of flexibility and focuses on ease of use and readability.

However, based on your description, what @trentallain said is probably true. Since you don't need to move them around, craft stuff, or probably store any information about the items, just keep a list of items. You can draw it all in a scroll-able list fairly easily too. (Just iterate through the list, drawing items and incrementing the y value). A good tip for that too though, is use enumerators to name your items so that it's easy to remember the IDs, as apposed to using random integer values.
 
J

John Smillie

Guest
Thanks everyone!
@Cloaked Games and @trentallain Could you maybe elaborate a little bit more? I'm still pretty new to Gamemaker, and while I basically understand what you're saying I'm having trouble translating that into code. I've looked for ds_list tutorials but I can't find one that isn't outdated.
 

Neptune

Member
In my experience, having an inventory is the easy part. Having it work professionally is a different story (stack counts, displaying information, hotkeys, splitting stacks, crafting, equipping things, etc etc).
I recommend using ds_grids though, they've been working well for all my needs.

If you mess around with ds_grids a little bit, you could probably quickly begin to create your own inventory system!
Note: You can store ds_grids inside of ds_grids. So each "cell" of your main grid, could contain smaller grids (like a 1 by 5 ds_grid), with that particular cell's (item's) information.

Code:
//create a grid
my_ds_grid = ds_grid_create(2,3); //Width then height (note the first value in a grid starts at 0,0 ...)

//add a value
my_ds_grid[# 0, 0] = "Sword";
my_ds_grid[# 0, 1] = 5;
my_ds_grid[# 0, 2] = "A shoddy blade.";

my_ds_grid[# 1, 0] = "Potion";
my_ds_grid[# 1, 1] = 20;
my_ds_grid[# 1, 2] = "A bubbling tonic.";

//retrieve a value
item_description = my_ds_grid[# 0, 2];
Once you formulate a system for storing your item information, you'll start to see easy ways you could then display the information however necessary (when the user hovers an item, or printing out icons into a visual inventory.
 
Last edited:
Top