[SOLVED] How do I save with multiple levels

I need help in saving my game
My game has multiple levels using the video tutorial about level selection

what I expect to happen is that if the player collided with the the door, the boolean variable of level 1 will be true making level 2 playable

My problem is how to save and load it so the player doesn’t need to restart the whole level again

Can anyone help me please, I need this to work for my school project any advice would be appreciated

Hi!

There is a way to load and save arrays and structures, but it’s much easier to save just single numbers or strings. So, instead of having the array World_1[ ] for storing the highest level, could you use the global number variable “HighestLevelAchieved”?

When the player character collides with the door, the HighestLevelAchieved is increased.

For Level-buttons the code should be something like this:

level_save

For Saving and Loading, there is an excellent tutorial video: Saving & Loading (Storage) - Intermediate Tutorial - GDevelop - YouTube

Hope this helps. :slight_smile:

Sure, I will try that later

Still cant get the save and load to work

Ok, can you send the screenshot of your code for saving and loading? :slight_smile: Let’s check what could be wrong.



Here is the events for my menu

1 - did you check that your actions are same as mine from screenshots?
Like it is save a text and load a text?
2 - in your game can you like unlock level 2 then do not play level 3 and go to idk level 6 and play it?
Like can you access any level or you need to complete level 2 to be able to play level 3 and you need to complete level 3 to be able to play level 4 and so go on
So you can’t access any further levels if previous level is not completed?

Yes, in my game you need to unlock the previous level to play the next one
I followed the screenshots and manage to save and load but only at the first time
The next time I load it won’t save and the next level is locked

So first of all instead of having boolean variable for every single level
You could simply make ONE variable a number variable
And idk call it LevelUnlocked
Now by default it is set to 0 so make event with
Condition
At beginning of the scene
Global Variable LevelUnlocked is equal to 0

Action
Change Global Variable set to 1
So it is never 0 and you start from 1

Next thing to do would be when playing level 1
Condition
Global Variable LevelUnlocked is equal to 1
Player is in collision with doors (or whatever here idk how you finish level but you put here whatever makes player finish level)
Trigger Once

Action
Change Global Variable LevelUnlocked add 1
Change scene to next level or level select or whatever

This way if you play level 1 and you finish it
You add 1 to LevelUnlocked
You won’t add 1 to LevelUnlocked if you finish level 1 again
And now you do the same for level 2

Condition
Global Variable LevelUnlocked is equal to 2
Player is in collision with doors (or whatever here idk how you finish level but you put here whatever makes player finish level)
Trigger Once

Action
Change Global Variable LevelUnlocked add 1
Change scene to next level or level select or whatever

And so you do not need variable for each level
Try it and come back here if it still only save/load once

Cause we just eliminated this way possibility of it being problem of other variables
And it will be WAY easier to fix now

Thanks I will try that later and post an update

1 Like

It’s still not working sadly

when I tried it on preview it save the first time and then when I tried to save it the variable won’t load

Did you check are your actions are save load text and not value?

BTW can you place text object somewhere and print LevelUnlocked variable to it to see what it says?

UPDATE I have finally fix the problem now

I just added the condition the global variable is set to 1 and it work

Thanks for the advices