How to make an inventory/chest inventory?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Amateur.game.dev.

I have recently created a 2d chest and would like to know how i can put objects in it that you can take out. The object will not be a random occurrence, but if you could I would also like to know how to make random objects appear in chests.

:bust_in_silhouette: Reply From: Surtarso

you can make a pool of objects you want inside chests and put them inside an array
lets say:

var chestitems_array = [item1,item2,etc]

than you randomize the array and pick the 1st item on it, as an example

func _random_item():
     chestitems_array.shuffle()
     return chestitem_array[0]

you can call that function with another var

var the_item = _random_item()

now for the chest to be usable just add an area to it and detect player entering and give him the item, or some key input or click.

If you want multiple slots on the chest you can just run this function for each slot or have another array with the slots and iterate thru the items array

This isn’t a simple chest that you walk up to and get given the object. You have to click on the chest which should bring you to the chest’s own inventory. I just don’t know how to do that.

Amateur.game.dev. | 2020-11-05 21:57

you can show the items inside the array to the player on click

without more details, ill assume the chest has 6 slots and you have 100 random items that could be there. you can just run that same function to each slot or make those 6 slots another array and iterate with the items array

Surtarso | 2020-11-05 22:12

In the specific chest I am talking about, there are no random items in there. Just a key.

Amateur.game.dev. | 2020-11-06 18:44