WARNING: LONG POST
Greetings,
To practice for more serious projects, I’ve decided to go to one of my older games and try to improve the inventory system I previously made in it.
It’s quite faulty, and suffers from several problems: Can’t arrange the items properly, doesn’t save between scenes, VERY unoptimal and messy code, etc (This was back when I was still a GDevelop amateur). But for now, I’d like to focus on trying to make the inventory arrange the items properly.
I tried using the built in inventory system, but the way my inventory is planned to function, it doesn’t work too well for me (Or at least not the way I’ve been using it). So I would like to use an array to sort my inventory (Or a structure variable in this case). It works how you’d expect: There’s slot 0, slot 1, slot 2, and so on.
So, what I would like to accomplish is to make it so that if I collect an item, it’s automatically put in slot 0. Once I collect another item, it will be placed in the next empty slot (In this case, slot 1). After collecting a third item, put it in slot 2, and so on.
If a slot is already occupied by another item, move it over to the nearest empty slot.
For reference, each inventory slot has animations according to what item it’s holding (Animation 0 = empty, animation 1 = item #1, etc.).
So far, this is the best I was able to do at the time. When the item is collected, add it to an inventory, and if the item exists in the inventory, put it in a random slot.
First screenshot: When the character collides with an item (The item changes based on it’s variable. There are more than 100 items btw), put the corresponding item in the inventory “MyStuff.”
Second screenshot: If the item exists in “MyStuff,” place it in a random slot (Notice my previous failed attempts to have the system globally loaded across scenes above the red comment).
So this begs the question: Can I make my inventory using a structure variable instead of the built in system? If this is already possible with the built in system, then how do I do that?
Also, unless necessary, please don’t just link me to the inventory example. That inventory has it’s slots mixed up, and I don’t need the extra code to drag, delete, or have multiple items (In my game, you can only hold one of each item at a time, and you can’t drop items once they’re picked up or drag them around).
Thanks in advance