[Resolved] Help! Saved Value Doesn't Persist Between Launches

I’m making a game where I simply want to save the number of the level to storage, and then when the game loads, load that number so the game can resume from the level the player is on.
This works perfectly when I keep the game open, return to the main menu and then resume, but as soon as I close and reopen the game, it doesn’t work and starts from level 1.

This is my code when a level is completed, followed by the code on the menu to load the value from storage:

The action appear ok. However, just screen snipping them isn’t sufficient.

Can you screen snip the whole set of events so the conditions are covered and include any parent events if those events you’ve posted are subevents?

Ignore this, see my next reply.

Flag my previous reply, I completely missed the first line of your screen snip.

You’re setting lastCompletedLevelvalue to 1 and then saving it to storage. When you restart the game, of course it’ll start at level 1 - that’s what was saved.

If you have a variable that holds the current level, then set lastCompletedLevelvalue to that.

This is the menu code here (replying in seperate posts because new user image restriction):

Each level sets that global variable to its own number. So like, level 3 will set that to 3. So when I restart, it should load the value of 3

The parameter in the box should be a text (in quotes). You’re passing a number.


If your all your scenes fit the pattern “ALn” where n is the level number, why not save the scene name instead of the level number, and open up the save scene name instead of calculating it?

There’s the GDevelop function CurrentSceneName() that you can use here.

So saving looks something like this (note it’s save a text to storage):

image

and loading looks like:


If you still decide to save and load using the level number, then here are some tips on these 2 events:

  1. Remove that first event and remove the condition in the second event that checks the value of lastCompletedLevelvalue. Doing this will cover both events.
  2. Add button state behaviour to adventure and credits, and use the “Is clicked” condition.
2 Likes

Solved! Thank you :3