Save/Load Game Issue!

Hi there! It’s me, back at it again in the Gdevelop forums! Right after fixing my last issue (Random coins falling from defeated enemies) I’ve hit another snag. Truth be told, these were things I was avoiding for a while because of my confusion with them, but. Here we are.

So essentially, I’m finally implementing a save/load system into my game. My Global Variables look like this:

I used This Tutorial on youtube to learn how to do more complex saving, which is why I put everything under a single Structure.

This is my scene variables in my ‘Farm’ scene. Your character lays down on a hammock, and triggers the save. Then once you die, or once you reload, you start back at this location.

And this is my very simple code in my ‘Title Screen’ scene. These are the only times saving/loading is included in my game, and I know this because I finally got off my butt to work on saving/loading today.

I’ve found some odd things when I load my saved game. I see some evidence that yes, it was saved. But other evidence of things that were not.

For example: I would turn off SoundEffects in a scene. I would also defeat some enemies, and pick up some Money. Then, I would break down a barrier (ForestDestroyBarrier, under the Quest section). After that, I would save, and restart the game.

When I restart the game, the barrier is still destroyed, but the sound effects are back on, and my money is back down to zero. I am pretty befuddled at what the cause could be. I’m probably missing something simple, but I have no idea the right questions to ask, besides just, explaining the entire issue I’ve found.

Thanks again in advance you guys!

It sounds like you could be over-riding the values loaded from storage.

To confirm, in the editor open developer tools (View > Toggle Developer Tools) or press ctrl + shift + i. In the window that appears (on the right?), select the Application tab, and then expand Storage > Local Storage > file://

One of the keys should be named “GDJS_save1”. Click on that and check the values are what you expect (there’s a panel along the bottom of the screen which displays the values in a nicer format)


If the correct values are stored, then run the game in debug mode and check the variables
image


If that seems ok, then you’ve got an event that over-rides or ignores the loaded settings. Check for typos (remember GDevelop is case sensitive).

I did as you said, and it appears that quite a few of the global variables are missing. How would I go about fixing that? Would I have to save them all separately in their own chunks?

(also for some reason SoundEffects=1, and although thats what I want, it’s strange that it doesn’t seem to be doing what it’s supposed to. I’ll double check my code involving that.)

And yup, I know all about the case sensitivity! I made that terrible mistake before, fun times!

Confirm the data is getting saved, and isn’t an old version of the data. to do this, delete the data from storage (via the developer tools) and save the data again.

If it’s not, try moving the trigger once in the event that saves the data, to the parent event.

Alright, I deleted that, and saved the data again… and now for some reason it came out with this:

It is clearly saving the global variables, and the ‘notes’ I have with them, but not the actual number of them. It didn’t save how much money I made, it just saved my description again. I have no idea what happened to change it so drastically.

Thanks for your patience and helping me out by the way, I really do appreciate it.

Best way to do this is to add delete Setorage button like


Change for your Storage name mine is game_data plus I clear al structure variables in Game

Wait. What? It’s saving the structure variable “Save”. Those descriptions/notes are the values.

I’m confused now. How and where are you storing the numbers? Can you provide a screen snip of the events that update the Save struture’s child variables with the various settings?

Actually. The moment I read what you wrote, I took a step back and went ‘wait… he’s right. They ARE the values, so what’s actually going on?’

It gave me the nudge I needed in the right direction and I figured it out. Essentially, for example, whenever I’d turn SoundEffects on and off, I had it under Menu.Soundeffects, not Save.Soundeffects. (It was an older state of what I was working with, I forgot to tweak some code).

Essentially my code was kind of janked up because I didn’t plan my global variables well enough for save states, and I gotta go back and make sure everything matches. When they do match, they save just fine! Which makes sense, but I didn’t realize they weren’t matching.

Thank you, sorry for any confusion! You really did help a lot, it’s now working like it should!

3 Likes