[Solved] Make a "you won" scene after each level that lets the player click a button for the next level, or a button to a scene of all unlocked levels/

Do I need to have a different “You won” scene for each level? It looks like I can just have the same scene and it auto updates with the best time for what ever the last level played was, but I would need to have a button to select to play the next level on that screen. As well as a button that leads to a list of all unlocked levels they could select from.

So I also need to know how to make a scene that shows which levels are locked and which are unlocked.

How do I do this?
Thanks!

I’m new with Gdevelop and I don’t know if my explanation will be the best way to make this, but lets go.

You’ll need use Global Variables to make that: Global variables [GDevelop wiki] (compilgames.net)

Here an simple example, but obvious you don’t need make the exactly same thing like I did. It’s just for you can get the logic about global variable more easily.

Global variables can be accessed from any scene in the game!

I Created a “Level 5” scene and used a global variable type “boolean” (you can just choose TRUE or FALSE for that variable. Nothing more). So, when the boss is died I changed my global variable “Level 5 Completed?” to TRUE.

I created a scene with name “List of Levels” for player can choose what level he will play. Of course he can’t choose level 6 before he finished level 5. So, if Global Variable “Level 5 Completed?” is true the animation for “Level 6 button” will be “Open” and when he clicks on it… Level 6! Otherwise with variable “Level 5 Completed?” FALSE will be animation “Closed” and if he clicks on it nothing will happens.

You can look for “Character selection” on EXAMPLES. It’s simple and maybe help you to understand better.

1 Like

Thanks for responding. With this method, would I need to have a boolean for each level within each level’s scene as in your first screen grab, and have one for each level on the “you won” screen the events you listed above in the second screen grab?

If I understand correctly: no. I created only one global variable “Level 5 Completed?” and changed it to TRUE. It can be accessed and changed from ANY scene in the game. So, in “List of levels” i checked it.

With my explanation you’ll need one global variable for each level.

No to which question. I’m confused.

You asked if need makes a Global Variable to each scene and for each level on the “you won”. You just need make a global variable to each scene and acess than in events of “you won”.

So if a player closes the game, the global variable for each level saying if it’s been completed or not will be saved and remembered when they load up the game again?

For this you’ll need use the “Storage” events to save and load.

Wiki: Storage action explained [GDevelop wiki] (compilgames.net)

Here is a tutorial on youtube: GDevelop - Save and Load Tutorial - How to Create Checkpoints - YouTube

And you can also look on Gdevelop on example “Character selection”.

I’d look at using one global variable, max_level_unlocked, and setting the button/text accordingly. I’d also give the level selector text an instance variable that hold the level it represents. So :

  1. Add a global number variable :


  1. Add a text object (I’ve named mine LevelSelector) to the “you won” scene :

image

image


  1. Add an object number variable named Level to the LevelSelector object :


  1. Add as many instances of the LevelSelector to your scene as you have levels, and set the instance variable Level for each LevelSelector in the editor. If you like, you can add a button image behind each text object :


  1. Add the events, that follow on from your other thread :


You’ll need to add code to save and retrieve the maximum_level_unlocked to and from storage if you want it to persist when the game is closed and opened again.

1 Like

Thank you! I’ll let you know how it goes once I get through it all.

For the following part:

Does that use the write to json file method you showed me in saving the “best time” thread?

Yeah I did the same thing. It is good because you can use it as a level selection screen too. Also it is good for when you have more levels like over 10 and don’t want to clutter the scene that is shown after players win/beat levels.

1 Like

I am leaning towards having a separate level selection page and on the “you won” page just having a “next level” button, and a “replay level” button along with a “all levels” button leading to the level selection page. I am hoping to have at least 20 levels to start with.

great
I wish you luck with it

1 Like

You won’t need use the JSON bit, you can just write it straight to storage.

1 Like

I assume I did something wrong again. Nothing happens when I click on a level that shows in green, when I would expect it to load up that level.

I am using a separate scene now for the level select, instead of having it on the “you win” screen. Could that be why?

Any level, or just the highest numbered green one?

The final condition is less than or equal to, not just less than.

Thanks for catching that. I fixed it, but I’m still not getting a level to start when I click on any of the level text objects. The red or green. When I click on the highest level green one, the next red one turns green. And so on. I can get them all to eventually be green, but none send me to an actual level.
I tried loading from the opening title scene and play a full level just to make sure it wasn’t related to just loading the one scene.

Do you have scenes named level1,level2, level3 etc?

HAHAHA! It’s my classic mistake. It just dawned on me (after reading what you wrote) that I called the levels “Level1” etc, not “level1”. Fixed the capital L, and now it works when I click on a level text object.

But, it didn’t unlock the third level when I finished Level2, it didn’t unlock level 3. Shouldn’t I have something that gets triggered at the end of each level to unlock the next? Maybe add the action you mentioned about the max level global variable to the same event that triggers the end of a level?
I tried putting that same action as mentioned above, but that didn’t work either.

In your screen snip, the last event is at the same indentation as the first 2 events. In my screen snip, those indentations are different. You’ll need to fix yours.