Jump to content

saving current level?


Mike018
 Share

Recommended Posts

I have 8 levels and I'm trying to make it so that if a user exits and comes back, the level they were currently on is started instead of going back to level 1. I don't know how to get my level variable to either stop resetting the localstorage info or the localstorage info preventing my currentLevel variable from increasing

init: function(currentLevel) {
    this.numLevel = 8;
    //currentLevel = +localStorage.getItem('TwoBladesCurrentLevel');
    this.currentLevel = currentLevel ? currentLevel : 1;
    localStorage.setItem('TwoBladesCurrentLevel', currentLevel);
},
if(this.currentLevel < this.numLevel) {
    this.levelComplete();
    this.currentLevel++;
}
this.next.events.onInputDown.add(function(){
    this.game.state.start('CampaignState', true, false, this.currentLevel);
}, this);
Link to comment
Share on other sites

Without more code it's hard to diagnose what's happening. Since you're the only one that gets things or puts things in storage, it's more a matter of controlling the flow around loading and saving the value than it is something particular to localStorage.

Like, it looks like you're passing in the exact value in your game.state.start call. What if you passed in this.currentLevel + 1? Then you could compare that to the value you pull from localStorage and if one is bigger than the other, use that?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...