Basic, but dynamic, inventory

Hello. My first post, and my first prototype. Here goes! I have a simple 3-slot inventory system.

  1. A ‘InvSlot’ UI object that has 4 animations. Empty, crowbar, banana, book.
  2. I have 3 instances of the slot on the scene with instance variables, ‘InvSlotID: 1, 2, 3’, ‘InvFull: True/False’
  3. The player collects an item by colliding with it. A global variable changes (item collected True/False) for consistent inventory between scenes.
  4. The object is deleted from the scene and the InvSlot object animation changes to show the item.

Great! But… each item has a specific slot. Items don’t appear in the first available empty slot. If the player picks up the banana first, it will appear in the second instance of InvSlot, and the book can only appear in InvSlot instance 3.

Can anyone help me to make the inventory work so that whatever item the player picks up, it will occupy the first available empty slot?

Here’s an image of the events for this basic inventory. Many thanks for any help anyone can offer.

nice! you can also use the built-in inventory feature in gdevelop. here’s the link to a video, hopefully referencing what i said.
https://www.youtube.com/watch?v=UcI4qZ4TAyY

Thanks for the quick reply. I’ve seen that video before. It’s great, but unfortunately not quite what I’m looking for and it doesn’t seem to use a built-in inventory system.

My game is a platformer, with a small 3-slot inventory always visible at the top left of the screen. The three slots are empty to start with, but get filled when the player collides with an item. It works, but you can end up with this (second row): if you collect the banana first, it will have empty slots to the left and right.
slots
I would like the first item - regardless of what it is - to check for the first available free slot.

PS. Please excuse the terrible placeholder art!

i think that’ll be cured via the built in inventory server, i assume this is the video.

That video shows an inventory working, but doesn’t show the events or explain how it works. But thanks for your quick replies. I will keep trying to figure it out. I’m very much a beginner and perhaps I am leaping in at the deep end with inventory stuff.

i dont see any video saying “How to make one with the built-in inv system” but i am also a beginner and think this community is small

I don’t think there is a GDevelop built-in inventory system. It has to be created. I will post an update if I work it out.

Sure it does! as below, what version you use?
Screenshot 2022-05-21 024653

Ah yes. I found that. Weird, it’s not mentioned in any tutorials I have seen about inventories, and it is not an object type you can drag onto a scene. It seems to be a place to hold information, like variables do (or perhaps more like an array). Doesn’t solve my problem, but it’s interesting all the same. Thank you.
https://wiki.gdevelop.io/gdevelop5/all-features/inventory#adding_removing_and_manipulating_items

I seem to have cracked it! I re-watched the first video you posted and came up with this:

Now it doesn’t matter what order I collect items. Each item collected will change the first available inventory slot instance, from left to right.

The inventory slot object and items object have 4 animations each. The animations match ie. crowbar item and crowbar inventory slot have the same animation number (I couldn’t work out how to do it based on the animation name because ‘Items.AnimationName()’ produced an error. Perhaps this was phased out; the tutorial is two years old.

I have no idea how the banana and crowbar would shunt to the left if the book was handed back to the librarian… but at least I have had a breakthrough. This morning I thought “If I can get an inventory and dialogue system to work then I can probably make a game.” I’m starting to feel more hopeful.

@worriedpixels, in the GDevelop examples page, there is an example project which seems almost exactly what you’re trying to achieve.

Or have I missed something?

You have, but thanks :wink: When the items in the example are clicked they appear in designated boxes, not the first available empty box eg. click the top left banana, it appears in the bottom left slot. I was hoping for a dynamic “use the first empty slot”, so you don’t end up with awkward empty spaces to the left and right of an item.

I may have come up with a solution using the FlexBox extension, which positions objects inside a box and if one object is removed the remaining objects close the gap… but I don’t yet know how to place things inside the FlexBox using events (hidden objects still occupy space that the flexbox takes into account, leaving award gaps again). It works in my scene, though, just as I need. If I can spawn an object inside the flexbox using events, then I’ll have exactly what I need.

No they don’t - they are are placed in the first empty slot, starting from the bottom left in a clockwise direction. I suspect that’s the order they were placed in the scene in the editor.

Oh yes! The clockwise thing threw me. It looks way more complex than I need, but perhaps I can work out how to make my simple inventory from looking at the events in the example. Thank you.

Follow up: I experimented with the FlexBox extension and it worked out.

The inventory items are created when the player collides with their associated items in the scene. The player can collect them in any order and they (FlexItems) appear left to right inside the FlexBox container, all on the same layer.

I created another object that if the player touches will delete the banana FlexItem. The remaining FlexItems fill the gap left behind.

That’s a nice easy way of having a simple “Does the player have the three ingredients to make a cake” kind of task I was thinking of, and it doesn’t matter what order they get the ingredients or if one is removed - there will always be a neat row of items. Thanks for your help today. It’s been useful to chat about what I was trying to do and get suggestions and ideas.

you’re welcome if i helped!

you can use animation numbers as variables to make an inv sys

btw may i have the link?

Hello. What link do you mean? Thanks for the animation number idea. That would be better than having separate objects for each inventory item. I’ll experiment with that today. I’m guessing the expression would be

Items.Animation(3)
or perhaps
Items.Animation("Crowbar")

Link to your project, mayb not now because I am on my phone rn.