How can I unlock levels based on high score?

How can I keep different levels locked on the main menu and only have them unlock when the high score is a certain score? For example, if high score is 70, unlock level 2. When high score is 80, unlock level 3, etc.

if high score is 70, unlock level 2. When high score is 80, unlock level 3, etc.

You said the anwser is your question.

Use a condition, if your variable score is more than 70 with the mouse is on bouton for start start lvl 2.
It’s basic and working. You should read about variables, because all game use variable, and you need understand how use it.
http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/basic-game-making-concepts#storing_any_information_in_memoryvariables

Same for other levels.

Thanks for your reply. I understand what the algorithm needs to do, but I don’t understand how to build it. What conditions and events do I use?

Here’s how I handled it in my first game - although I haven’t published this version yet.

I made a global variable structure called “progress” with children for each level like:

progress

  • level1
  • level2
  • level3

And so on. You’re going to use this structure to control whether a level is unlocked or not with true/false or 1/0 values. You can just leave them empty since the value is 0 by default. If desired, skip level 1 in that list because it won’t need to be unlocked.

In the level 1 events to unlock level 2, you want to add the following:

Condition
Global variable HighScore is equal to or greater than 70

Action
Change global variable progress.level2 set to = 1 (true)

I would include an action to change the scene to the next level here too, but you’ll still need to set the progress for the menu. Repeat this for all subsequent levels.

For your menu, you’ll need some events to handle both the locked and unlocked states.
Mine is in a function; you can use that or an external event sheet.

The events there would be something like:

Conditions:

parent event

whatever your input method is: cursor/touch is on [menuitem], key press, etc

sub-event

Variable ID for the menu item?
Global variable progress.level2 = 1

Action
Change scene to "level2"

In a separate block or group, you can also set what happens when the progress.level2 variable is 0 or false (locked). Just change the menu link style to gray or something to indicate that it’s not available; maybe even a message such as “complete level # to unlock”.

Let me know if you have any further questions :slight_smile:

1 Like