• 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!

Advice on Chest/Container system

FacesOfMu

Member
Hi there,
I'm working on a sandbox game and trying to figure out some simple ways of handling chest/container type objects that store a bunch of other item objects persistently. I'd like some ideas on how people go about this.

Typically these objects that will be contained have multiple variables. When an item goes in a container, I could transfer all the item's variables to a table and destroy the object. However, that becomes really, really clunky when it comes to managing the table and trying to parse all the variables that objects might get.

Alternatively I could turn off all the things that make the item interactive (invisible, non-collideable, etc), and even push them to a different layer, but I'm just not sure if that's the most efficient and "normal" way of going about this.
I especially want to be thinking of players that may hoard lots of containers with lots of contents in the long run.
 

Gamebot

Member
A persistent parent/control object would be the way to go, you can use a global array or ds_map.... I would go with an array or ds_map anyway. To answer better, the question you are asking is how to do an inventory within many different instances? Or is it a random loot box?
 

FacesOfMu

Member
A lot of the guides and tutorials suggest arrays and maps, but the items they're holding are often one dimensional ("sword", "apple", "arrow"). I want to have multiple chests and containers that hold large varieties of items, eg
Sword, Iron, 5-10 damage, 3 quality, 57 durability, 20min poison duration, ice enchanted, enchantment duration 30 mins, made by Bob
Salad, 30% left, 5 quality, 30 durability, frozen, made by Bob
Watering Can, copper, 4 quality, 100 durability, 50% full of blessed water, made by Jane
etc etc.

What I want is to do as little parsing and table importing and exporting as possible. I'd really like to maintain these item objects in their instance state and not have to write multitudes of scripts covering moving every item type and their variables into and out of grids or arrays.
 
B

Bayesian

Guest
What I want is to do as little parsing and table importing and exporting as possible. I'd really like to maintain these item objects in their instance state and not have to write multitudes of scripts covering moving every item type and their variables into and out of grids or arrays.
Then nest the DS/array, for example the player's inventory could just be a 2d array that stores type and data. type is just an identifier(string) that tells you how to unpack the data which is another DS/array. That way when moving things to and from the players inventory to chests you just need to copy two array positions directly.
 

Gamebot

Member
As far as the containers themselves are these "randomized" at spawn? If so make a global that separates "Type", "Objects", then max number each object can have.

Something like:

Weapons Bobs
30 12
Arrow Salad
Teddy Bear Water Container
Book other bob stuff


For each instance in a script get all of the top row randomize them in a ds_list to get random items. Loop through list to find proper max number, choose random number. Now return an array of both to each instance. You can at game end or quit...save all of that to an array. Name the array for that instance the location, x32y52. When you load simply loop through all containers get x and y then add an x and y before each put together and done.
 
Last edited:
Top