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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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