Making a simple inventory

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

So all I want to do is an incredibly simple inventory for picking up the med kits, since it’s pretty useless when you have full health and find one I figure the player might want to use them later instead, all I’m looking to make is an incredibly simple Metal Gear One style inventory, I just want the item to appear once you collect it and the ability to use it, I figure this is possible, and I have the basic ingredients in my mind like puzzle pieces, I just don’t know which way to put them together, and all the tutorials I do find make much more complicated inventories that really aren’t what my game is going for. I’m assuming using an autoload script and some somewhat basic code it should be possible but I always overcomplicate it in my mind I figure someone here can help, basic idea is that when you enter the are of a first aid kit it gets added to your inventory and can stack up to 10, that and to pick up “key items” and remove them once you give them to the quest character.

:bust_in_silhouette: Reply From: Gluon

Yes this can be done very easily and as you say use an autoload.

First have an autoload script with a variable for your medkits e.g.

var MedkitsLeft = 0

Then when you have full health and your character interacts with a medkit simply increase this variable by 1.

Next have a canvas layer which will be in all your playable scenes. A canvas layer goes on top of everything in a scene and is ideal for a player needed inventory. In that canvas layer have an image of the medkits but not one of the medkit scenes rather just a sprite with the medkit in it and a label next to this. In your label simply have the code,

func process(delta):
    self.text = Global.MedkitsLeft

This will mean you will have a medkit showing on screen with a number next too it all the time but this will increase in number when you pick up a medkit.

Finally whenever the player uses one of these medkits simply decrease the number in the global script and the label on screen will increase and decrease as medkits are used or picked up.