Get back at the scene i left last, when i reopen the game?

I have 10 levels in a game.
For example, i exit the game at level 6. I want level 6 on my screen when i reopen the game.
Everytime i reopen, i begin with level 1, thats already unlocked. I want to get level 6 to be reopened where i left the game. help me with this.

Create a global variable g_current_level and set to 0, then every time you go to a level set g_current_level to that level number.
Store g_current_level in Storage
In your game logic, at the Begin of the scene check
if g_current_level has a value then change to that level number

hey! thank you, but can you give me a link or an example for the same?

You will need to learn the base concepts around file saving/loading rather than a specific example for this one thing, else you’ll run into trouble down the road.

I’d recommend reading up on the storage actions here:
http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/storage-action-explained#storage_action_explained
http://wiki.compilgames.net/doku.php/gdevelop5/all-features/storage#storage

And then look at the save/load and level unlock examples here:

thank you, but i have already seen these examples.
My problem is mentioned here, help me if you can.

Then you need to review the examples more and consider how you’re trying to implement saving and loading.

You should be saving your levels as they’re unlocked, and you should have events set up that load the most recently unlocked level. You will need to understand those fundamentals, and think through how you’re going to set it up, in order to proceed.

Unfortunately, there are a few dozen different ways this could be done, and I cannot create a whole method just for your specific instance. The level unlock example is pretty much exactly what you want, or it is at least a great place to start.

1 Like