Easy to understand inventory

Hi everyone. I've been learning how to use game maker for 4 months now
and I got quite further than I thought i would. Thing is, now I'm starting to
"really" learn how to do things in a semi-professional way.
I already have a character creation setup, and now I want to do inventory management.
I did it before and it works quite well. You can add items, buy items, it checks if items
may or may not be added depending on the available slots,...
But it's not perfect. What I really want is something like stardew valley, minecraft,...


So: an inventory with a couple of long rows of "slots". Each item "type" has a maximum amount before
it will fill up another slot. Also: let's say an item can only have 99 per slot. You should be able to select
9 of those, then move them to another slot. Leaving 1 slot of 90 and 1 slot of 9 of that item.

I can make it work perfectly without that "item maximum per slot". Item swapping and inventory
sorting is easy to understand now, but it's that "maximum per slot" that I can't figure out when
combining it with inventory management.


Currently I'm just using 1 small script, 1 object with a draw GUI and step event, and of course,
items to be picked up (objects themselves or in a store where the same properties are transfered to your inventory).


My inventory is basically a ds_grid. It "scans" through the rows and check to see if an item "add" is allowed or not. This involves checking if
a) the item is already there: just add to that
or
b) the item is not already there (and if a free slot is available)


if any of these 2 are true; the item is added in the amount specified, but it's easy to see you can have an infinite amount of each item type in your inventory that way. Item swapping is still possible and as easy as clicking and dragging the icon to another.


I've been searching for a "semi-simple" solution to do it myself, but all I can find in the market place is things that are either too simple, ot use waaaaay too many script to pull it off. I'm sure the math, script wise and ds_grid logic wise, is there.


Any tips?
 
When you get to the part where you're adding items to the slot, you just need something a bit like this (in puedo-code):

Code:
if the slot is not full
- Add your items to that slot, no more than could be added to fill the slot
if you still have items
- Find another slot
With a bit more detail.

Code:
max_items_add = slot_max - slot_current_items
if (items_to_add < max_items_add)
- add all the items like you do now
else
- slot_current_items = slot_max
- items_to_add -= max_items_add
- find a new slot to finish adding items
 
When you get to the part where you're adding items to the slot, you just need something a bit like this (in puedo-code):

Code:
if the slot is not full
- Add your items to that slot, no more than could be added to fill the slot
if you still have items
- Find another slot
With a bit more detail.

Code:
max_items_add = slot_max - slot_current_items
if (items_to_add < max_items_add)
- add all the items like you do now
else
- slot_current_items = slot_max
- items_to_add -= max_items_add
- find a new slot to finish adding items

This..... might work perfect with the "item swap/inventory management" i already have. Gonna try it tomorrow. Thanks!
 
Top