Is there an easier way to use “inventory”?
Currently my save and load looks like this:
That way it works perfectly and I have nothing to complain about.
But I realized that we have the “inventory” that following the wiki, at least I couldn’t make it work
Inventory [GDevelop wiki].
So I thought this way would be easier and practical for everyone who wants to save and load inventory items
Wouldn’t making a change within the GD code to improve this save and load part be interesting?
I tried to research more about it but I didn’t find anything that explains it in a simple and straightforward way, and the wiki explanation, there is a piece of code that we should insert the ToJSON, but it looks like there is an error in the expression!
As far as I’ve seen, the entire Inventory system events are literally just fancied up structure variables.
It’s just abstracting some of the events for you.
I would 100% recommend people experiment with and learn more about structure variables and ignore the inventory events.
especially because structure variables are the better/faster way to save all data, not just inventory data.
As an example:
- You can just create a structure named “GameSave” with children of “Slot1, Slot2, Slot3” etc.
- Then you have a structure variable named “GameState” with a child structure named “Inventory”.
- You create children within inventory for every inventory slot, and have each slot have a “quantity” and “name”.
- As part of your game, you update the GameState.Inventory.SlotNumberhere.Quantity whenever they add/remove an item, or wipe it entirely if the slot is emptied.
- As part of your save events, you just update GameSave.Slot1 with the entire contents of GameState. Now your inventory and all other variables you have in GameState are part of that save slot variable.
- You then just save GameSave (or GameSave.Slot1 if you’re keeping separate save files).
Those 6 steps would allow you to have infinite types of game data stored, including inventory ,without having to do separate save actions for each one. When you want to load the data, you just load your file into GameSave. When the player loads the save slot, you copy the data from the GameSave.Slot# over to GameState. That’s it.
(All of your logic would work out of GameState. Etc).
In my opinion, the inventory events just complicate matters rather than simplifies them.
Exactly what I think, so I made a request here to better adjust this code.
It should be much simpler, because as you said it’s too complex, and looking at code issues, I prefer a thousand times to work with variables and save them normally or solely, instead of using the current inventory, which for me, at least, should be a simple system.
As for this inventory system, could it not change how it works in the future?
Personally, I’d recommend the inventory events be removed entirely for a few reasons:
- I don’t think the original designer of the inventory system is still active in the community.
- It doesn’t seem to simplify anything for users, and in many cases is more complex than someone learning how to use structure variables.
- I’m not sure how you can simplify it without rebuilding it from scratch. I’d think that time could be better used by just writing up a tutorial on making an inventory using structure variables, and then using the left over dev time on other pending features/fixes/etc.
(keep in mind I have no say on dev choices, just listing out my logic above)
I understand your point. It’s weird also to have an option like that, and not be able to use it easily. Like me, I believe that several people have tried to use it because it seems simpler, and gave up on the way. Because at first it seems simple:
1- Add to inventory
2 - Save inventory
3 - Load inventory
But in practice, this doesn’t apply!