Inventory Help!

Hey there! I’ve been struggling with this all day, and I definitely need help with my Inventory system. Although I’ve seen and experimented with the Inventory example game, I still don’t understand how any of it is happening, and how to make it happen in my own game. Yes, even with the examples and comments. I also looked through the ‘How do I…?’ forums, and nothing seemed to explain what I need in a way I understood.

So as you progress through the game, you’ll get new outfits, but what order you get them will be more randomized. Essentially, you start with Outfit 1. And then, later on, you buy an outfit from a vendor, and no matter what design it is, I want it to go into Outfit slot 2, and so on and so forth.

Each ‘Outfit’ already has a ‘Tile’ be selectable, and an ‘Outfit’ object variable on top of each.

Truth is, despite looking at the example game, I still have no idea how to truly implement this into my game. It’s given me a huge headache since it seems so simple, and I just can’t seem to get it.

Related screenshots

(I’m aware why this second example doesn’t work, since it locks certain outfits into certain ‘Outfit’ variables. I know it’s a mess and I’d love to have a single Outfit variable for all the clothes, but even after looking at the inventory game I still just. Cannot understand how it works, so I struggled finding a way to make it work with the knowledge I already have, to bad results. I also attempted to have a ‘selector’ move from Outfit1, to Outfit2, and so on, but. Augh. It’s just a giant mess and nothing is working. I just want a supremely simple inventory set up, so I never have to worry about this again, and can add it to my other inventories too.)

Yall have always been a huge help, and I can’t avoid creating a functioning inventory any longer, if I want to keep progressing with the programming of my game. I obviously need to start from absolute ground zero to understand this. Please help!

Now I’m off to have an ibprophen for this darn programming headache.

1 Like

hello, good morning,
I recommend using one object for all Outfits1-6
just assign an instance variable to keep track of each.
and also I recommend using an inventory variable like this:

so each time you add an outfit to the inventory you would check if a slot is not empty and repeat it until finding an empty slot
and for the actions this is how it will go:
1-so you’ll add a for each instance block
(if global var (save.outfitrecieved[“slot”+object.var]) =/ “empty”) |||| set the animation of the outfit to save.outfitrecieved["slot"+object.var]

I hope it helped : D

Hi. I can’t help you with the implementation of the inventory system in your game, but I can attempt to explain how the inventory example works.

  1. Each inventory slot has multiple animations to display either empty or the item stored in the slot.
  2. Each inventory slot has an object variable called “nameofitem” to store the name of the item displayed in the slot
  3. The example uses the Inventory storage to store number of items. The name of each item in the inventory storage is the same as the value of the object variable “nameofitem”
  4. Each item you can collect also has an object variable called “name” to store the actual name of the item
  5. Each item you can collect also has an object variable called “quantity” to store how many items you collect. For example if it’s money, you may want to collect 10 or more.
  6. When you collect an item, you go through each slot object and compare if the value of the object variable “nameofitem” is the same as the item’s object variable “name”.
  7. If the name is the same, you increase the number of items in the Inventory storage by the value of “quantity”. If you want to store only 1 item in the slot, you don’t want to do this but step 8.
  8. If no slot with the same item found, look for an empty slot by comparing if the value of the object variable “nameofitem” is an empty string “”, that means the slot is empty, then you add the item to the empty slot.
  9. When you add the item to the empty slot you do 2 things. 1 is set the value of the object variable “nameofitem” to be the same as the item “name”. 2 is add the item also to the inventory storage using the item “name” and the value of “quantity”. So then you find an item in both the slot and inventory storage by using the name.

This is how you add items to the inventory and inventory slots. To be honest it is overcomplicated because you don’t actually need the Inventory storage, when I made the example I was just curious if I can get the example working with the Inventory storage, it was a new feature in GDevelop. But you can use just object variables instead.
You also don’t really need the object variable “nameofitem” you can just work with animation names instead.

So it is not a good example how to make an Inventory or how to use the Inventory storage to be honest. The example team should have replaced/improved this example long ago.

Anyway I hope my explanation helped to clear things up a little. In case you need further explanation regarding the inventory example, let me know what is it that you don’t understand about it.

Good luck. :+1:

Okay I’ll say you’re DEFINITELY helping a ton! There’s still some things I’m not quite getting however, so I hope that’s alright!

This is what I wrote down, and I’m still getting lots of red. I’m unsure what I’ve done here, and to me it looks like gibberish, so I’m sorry about that.

This is how I restructured my OutfitsRecieved global variable, which is MUCH cleaner and makes me quite happy.

In good news, I already have all the outfits underneath a single variable ‘Outfits’ as shown above, but I’m unsure how to combine it all. Also, my outfits_slot object looks like this:

I’m assuming that. When Gdevelop senses a global variable slot is ‘empty’, it will edit the text ‘empty’ to a different text, such as ‘Angel’ for an outfit, and a separate condition will read ‘Angel’ for that slot, and change the visual. But I’m still clueless on exactly how to program it to make it happen. I’d love everything to be in a single outfits_slot object. I have 8 outfits_slot’s created at the beginning of each scene. How will Gdevelop know which one is which, and keep it organized? Do I have to somehow include each to have a different object variable from each other?

I hope that made sense! I’m just trying to process what you’re explaining and see if I’m getting it right.

Hey thanks so much for the wonderful explanation! I’ll go through the steps you gave me and clear my brain a bit.

  1. In good news, this one I understood pretty well! Nice and simple, which I really like.

2 and 3. I assume the ‘nameofitem’ then, is purely related to the “name” of the object you collect. So there is a condition that will check the name of the object, and change the variable ‘nameofitem’? (Like collision with ‘Apple’, then it changes the ‘nameofitem’ to ‘Apple’ on a slot object variable, which in turn changes the animation of the slot to ‘Apple’. Right?

  1. Okay actually you just answered what I asked! That makes sense to me.

  2. That also makes sense! I assume you create the object variables at the beginning of the scene?

6,7 - okay that makes sense!

  1. AH, okay so “” means a string is completely empty. I sometimes toss in little notes to myself on global variables, so that makes sense.

  2. Okay, I think I get it! I’m still unsure how Gdevelop differentiates two slots from each other. Like how it knows to go left to right, or how it remembers a certain slot held a certain item, even though all slots are a single object variable.

Okay now I read your last few paragraphs, and I couldn’t agree more. It just feels extremely confusing and complicated, especially to us first-time programmers. I think overall I’m getting a better concept of it, but certainly not enough to fully know how to use the Inventory example, which is why I’m quite happy with avoiding Inventory storage and going around it with object and global variables instead.

1 Like

My structured variable is like this:
And there is row1, row2, row3… column1, column2, column3…
Now how do I check if the ‘name’ of every child variable is empty?
I can get it like this:
But that only give me one result, and can’t check all the child variable.


you copy- paste the text that I sent you have to have a name for your child variable

yea i feeels you none of the things out there are really clear

hopefully there would be other ppl that create and make things that are very very clear, and shows the steps of how to do things

and explain things fully (hopefully in videos) =)

  1. Using the For Each Object event you can iterate through each instances in the order they were created.
  2. Object variables are unique for each instance, it is not shared. I guess Instance Variable would describe better the variable but they choose to call it “object” variable because each instance inherit the object variable but it is unique for each instance and not shared.
  3. At the beginning of the scene, we iterate through each instances and create an “ID” object variable and increment the value of ID by 1 for each slot so we get a unique value for each instance.
  4. To save inventory, we use the storage events to store the value of “nameofitem” in a group called “nameofitem”+ “ID” and the quantity in “numberofitems” + “ID” of each slot in web storage. Remember value of “ID” is unique for each slot and we are going to use it in 5.
  5. To load inventory, we iterate through each slot and use the ID value of the slot as reference to find the group “nameofitem” + “ID” and “numberofitems” + “ID” in storage and load the item name and quantity for each slot. Again the value of ID is the key to reference values in storage.

If you are uncertain about point 4 and 5, take a look at the save-load example and probably there are also some tutorials how to use storage events and I also recommend to read the documentation on the wiki.

Basically you can imagine web storage as a single text file in which you store all values in groups.

“nameofitem1” = “apple”
“numberofitems1” = “2”
“nameofitem2” = “pearl”
“numberofitems2” = “1”
“nameofitem3” = “melon”
“numberofitems3” = “2”

And this is how you store the item and quantity of each slot in web storage and the number at the end of the name of each group is how you reference them.

Hey everyone, so yup, I did the ‘For Each Object’ and created unique ID’s for each outfit_slot by doing so, and I tested it to be sure it worked. And it does! Now after lots of tweaking from everything I read, triple checking back through examples and whatnot, this is how my code looks now:

It absolutely works, and I’m so, SO close to having it work completely. As you can probably tell I took bits and pieces of the examples, plus what yall have been talking about here.

My final bit, is to save each outfit under one of my Global variables.

Just like my example from a few posts ago, I have the Save.OutfitsRecieved.slot1, slot2, and on and on. Also, I hope I did this correctly @potato-coder, I changed up how I’m going about the inventory in a way that worked better in my head and it makes sense for me now, the last step I’m trying to do is to ‘save’ the correct image to the correct outfits_slot. I tried to use your example, and a child variable, and there must be something basic I’m missing. I apologize for that.

Essentially, if the id of outfits_slot is = 1, I want the text of the global variable of slot1, to be changed. I tried to do the Save.OutfitsRecieved.[“slot”+outfits_slot.Variable(ID)] but since it’s red, I clearly did something wrong. If I can get this last step in, I feel like I got it all taken care of, hard part being over.

So is it possible to tell Gdevelop to recognize what number is after Save.OutfitsRecieved.slot, and compare it to the outfits_slot ID number? And if they’re the same, to change the global variable to text “Original”?

1-you did everything great just put a ToString() and put the object variable inside of it cause it only accept strings
it will look like this
(just add to string around it that’s all)

2- when your rendering the names just put a condtion if global var slot = “empty” so you check if its empty so you can render orginal

Thank you so much! The code looks so clean and wonderful, and it’s all working properly now!

My last, last thing I’m trying to code, is when you switch to a new scene, that all the saved Global Variables for the inventory go into the correct slot at the beginning of the scene.

This is how I tried to code it

But I can tell it’s off, since it isn’t working, and I don’t think I wrote ‘the variable id of outfits_slot’ correctly. Help for this final step would be very appreciated! I’ve never worked too deeply with the more complex variable formulas (or many formulas at all really) so it’s been a headscratcher still.

I’m so close, thank you so much for all your help!

your so close, so your first gonna copy this

and then paste it here and here and here

and then delete both conditions,

and its all done : D

Hey! Got busy, sorry it took me a few days to get back to you.

Unfortunately, that code doesn’t seem to work. ): Here I’ll show you all my examples.

This is my current code. I can’t move anything around or it seems to break beyond repair, so this was the most functional spot for the code I could have. It includes everything we’ve done so far!


This is what it looks like when I change outfits, and open my menu to look at my items. The two ‘text’ code up at the top, are the ID, and nameofitem.

This is what happens when I leave to a new map. The inventory code is universal by the way, it’s in an external event sheet included on both maps.


I really do appreciate all the help!

i dont get whats not working

Oh, crap! Well I guess we’re both in the same boat. I’ll try to figure it out somehow. Thanks so much for all the help.

The events under the [at the beginning…] don’t look indented. Are they supposed to be sub-events?

[Trigger once] doesn’t work well inside [For each] events especially without other conditions.

I can’t see the code for the outfit is empty or not empty events but the 2nd group doesn’t look like a subevent of the [for each] Personally, I would make each empty check a sub-event of the [for each] and leave the [for each] itself empty.