level unlock help

ktfrightktfright Member Posts: 964
edited November -1 in Working with GS (Mac)
preferably at either eastbound, firemaple, and Tshirtbooth, but anyone with the answer can chime in also...

I'm making a new game with multiple levels that need to be unlocked by beating the previous level. How do I save the level and keep it unlocked? What ways did you guys go about it?

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    The way I did it was to have a variable (boolean) called "level x unlocked" (where x is the level number).

    Also have a 'level complete' variable.

    The level complete is changed to 'true' if the level is completed (whatever the 'win' scenario is).

    In addition, the 'level x unlocked' variable is set to the next level (if you've just completed level 2, level x is level 3.

    Then on your level select screen, have a button for each level. Level 1 is always unlocked.

    Each button should have the rule:

    If button is pressed, and level unlocked is greater than the level selected, then go to level.

    (e.g. if level 2 button is pressed, and level x is greater than 2, then go to level 2).

    Hope that makes sense. I've been up all night so it might not be very clear, but should point you in the right direction I hope!

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    There are a few ways to go about it. The two most common ways are either to force the player to play through the levels in order, or to allow them to play them in any order.

    It is much simpler from a programming perspective to force the player to move through the game sequentially. That way, like QS says above, you just need to track one number - the current unlocked level. You would make this global attribute an integer. It would start at 1, since the first level is unlocked. Each button on the level select screen would have an attribute called something like 'myLevel'. It would be set to the number of the appropriate level.

    The logic would look like this

    When self.myLevel <= game.currentUnlockedLevel
    Show unlocked graphic, button is enabled
    Otherwise
    Show padlock, button is disabled

    The other option, allowing the player to play any level they want - but keeping track of the ones they completed - is a little more tedious. You need to keep a separate boolean attribute for each level like this: level1, level2, level3, etc... And you need to add a specific Rule to each button instance like this:

    Inside button 1:

    When game.level1 is TRUE
    Show my 'complete!' indicator ( a check mark, a little star, a smiley face, whatever)

    Joe

    Every button instance needs a Rule like this.

    In my latest game, stunt squirrels, I am tracking 180 different attributes. It gets a little bit tiring trying to keep track of everything the player does!
  • VmlwebVmlweb Member Posts: 427
    I just stored it in a real attribute called LevelsUnlocked.
    When you got to the level select screen the each number checks if LevelsUnlocked is higher than the number it is. If it is higher it'll destroy itself.
    Then every time you unlock a new level it adds 1 to that number.
  • butterbeanbutterbean Member Posts: 4,315
    so the one attribute game.levelsunlocked is integer right, so each time a person finishes level one, you change the attribute to a 2 and so on?
  • EastboundEastbound Member, BASIC Posts: 1,074
    Yes that is what I id, butterbean. I had an integer go up with each level as you progressed, and then it would save the variable.
  • ktfrightktfright Member Posts: 964
    Thanks guys, Ill try all of them out to see whats best!
  • butterbeanbutterbean Member Posts: 4,315
    What's the easiest way to do the padlock? Do you have an image of a padlock over the actual level select icon, and destroy it once the player has met the objective?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @butterbean: yes, I would make a padlock actor and set its alpha to 0 or 1 depending on whether it is unlocked or not. It's alpha would initially be set to 0.

    The padlock actor prototype would have a Rule like this:

    When self.myLevel <= game.levelsUnlocked
    Change Attribute: self.Alpha To: 1

    You would create an integer attribute inside the prototype of the padlock actor called myLevel. Then you edit that attribute in each instance on the stage.
  • ktfrightktfright Member Posts: 964
    Big problem!!!

    I got the whole saving and unlocking down to a point, but randomly today I wanted to do a quick playthrough of my game, and I noticed that when I do a level and beat it, it unlocks a level, but when I beat a previous level, the level I unlocked becomes locked again.

    I think my rules are set so if the player beats a boss, change the global attribute LevelsUnlocked to whatever number level is unlocked (there is where the problem may be at)

    I really need some help on this. Anyone got an idea?
  • rebumprebump Member Posts: 1,058
    Umm, where LevelsUnlocked is updated add another rule to only do the update of LevelsUnlocked if CurrentLevel is greater than LevelsUnlocked. Thusly, you only update if the newly unlocked level is higher than the previous unlocked level.

    Since your "change scene" behaviors are likely to the next scene this should work fine.
  • ktfrightktfright Member Posts: 964
    that might work, but LevelsUnlocked changes when a boss is beaten, so i am having problems with this still.
Sign In or Register to comment.