• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Global Inventory System

Omninaut

Member
So i should start off by saying ive looked up almost every inventory tutorial and have tried to learn all the data structure types but im still struggling to adapt something into what i need.
From what ive seen Structs seem to be the best method for when items have alot of variables and info attached to them. I followed this tutorial:
But only the part about setting up the constructors. My project is setup in a way to where i need every object in the game to essentially be one object but have its variables replaced with the info from an item struct. I also need to create each item in the very beginning of the game in an initialize script. This is because not only can the player have an item but the obj_item can be placed on the ground, shop keepers and other NPCs have an inventory, chests and storage things can have an inventory, so it needs to be possible for everything in the game to have any item. But i dont want to create an item more than once. Simmilar to a bethesda game having a list of items and being able to pull an item from a list (item.#) would be perfect.

I dont want to create a thousand global variables and have to reference them in order to pull the info so im looking into data structures as a global.item to store the structs. So then i wouldnt need global.itemburningsword3, but instead global.item.241 or something. The issue is im not sure how to set this up and have it work well with constructors, or rather which data structure would be best. I dont think id need more than 1dimension because i just need the list to tell me which struct im referencing and thats it. Then objects that store things can use 2d lists to see which and how much of each item it has. Any thoughts? Thank you all in advance!
 

Gamebot

Member
First off you might want to look at the difference between an instance and an object. To put it short you can have one object player for an eight player game. In which each would have it's own sprite, controls ECT...

As far as a beginner tutorial on structs there is a decent example of usage for many instances all with different names and each having different health.

And of course my phone is going to be retarded so look up...

"Funbox structs" on You Tube. Personally I would watch all of it.

EDIT:
It might be as simple as setting up a controller or parent object as well.
 
Last edited:

TailBit

Member
The item list is usually just an array global.item[241]

If you want the Skyrim way then you could go for it:

Then your chest could have an index in their creation code,
chest_loot[index] = [ loot_table_index, first_time_loot_table, have_opend ];
When any container is clicked/opened then it checks a list of previously opened containers and try to find its entry, if found, then it moves itself to the top and update the time:
ds_list_add(old_containers,[room,CONTAINER.chest,index,datetime_get_current(),slot_content]) // or ,CONTAINER.drop,[x,y],
If it didn't exist then it creates the slot content of its loot table and fills it before adding itself anyway

Remember 2 in-game weeks worth of opened slot_content

When clicked then it hooks up the slot_content to the container struct of its type that I have pre created in the control object, so I don't create more inventories, only one for player, equipment, chests, shop that swap what slot_content it is linked to

But yeah .. that is one possible way of doing it .. good luck.
 
Top