Hello, I’ve just started learning how to use Gdevelop yesterday and was hoping someone could help me. I’m creating an inventory system for an android game and am trying to figure out how to save the “items” that a player gets, so that they’re still there after the game is closed and reopened.
Each inventory slot is the same object, using different animations, so if you get an item, it changes the first available empty slot into the animation related to that item. Each slot is given an ID at the start of the scene through a repeated +1 variable action. All of that seems to be working great.
What I’m kind of lost with is figuring out how to combine the individual IDs and current animations, into something that I can save and load, if that’s even possible. My idea was to save the data every time an item is added and load the data at the beginning of the scene, but I don’t think I fully understand the difference between “storage name” “group” and “text” when looking at the read and write actions. Also I imagine that when I write something with a storage text, every time I write to it it’s just replacing what was there before? Really having a hard time wrapping my brain around this xD
Okay, I have is kind of working now. It seems to be working good testing it in gdevelop but when I export it and try it on my phone it’s unreliable. I can close it and open it and the inventory items do stay in their respective places most of the time, but sometimes it messes up, and a couple rows will randomly be one animation which isnt how it was when the app was closed. I’ll include some screenshots.
Edit: One more update just incase someone tries to figure this out, the exact problem I seem to be having is when I open a fresh install of the APK on my phone and add a couple of items to the inventory and then close and restart the game, the rest of the inventory slots turn into the last item that was added. That issue ends up not being reproducible after I’ve played with the inventory for a while, so clearly it has to do with the inventory slot instances not working properly right off the bat. I’ve tried to add some conditions to make everything bypass slots that haven’t been used yet, (like, when an “item is added” a variable on that instance is set to “yes”, and then there’s a condition that checks to see if that variable is yes before it changes the animation of that slot, but that just seems to break it entirely and nothing is saved anymore.
Edit 1 last time: Ahah I got it! I’ll add it here just in case anyone may find this helpful. I was only saving the animation of the slot that was being changed each time an item was added, so at the beginning, other slots that had nothing loaded for them were just taking the animation of the last thing added. I changed it so it looks like this and it works perfectly now :
Basically every time an item is added, it specifically goes and cycles through each slot and saves ALL animations, including the empty ones, so when it loads them they all have something to load.
I don’t know if it will make a difference but I noticed you used trigger once when adding and removing mats but you don’t use trigger once when writing the data, so it’s running the entire time the conditions are met (when the touch/press is occuring).
It might also explain the strange behavior (sometimes it works sometimes it doesn’t).
You could try adding a trigger once to it, or using a “touch/press released” condition instead of “touched/pressed”