How do I use webstorage on level select

0 favourites
  • 12 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • Hi how do i use webstorage to keep the levels unlocked once they have been passed. I used a simple level select tutorial i found where each level has its own global number ie level1,level2,level3 ect. they all = 0 till you pass the level and it will add 1 to unlock the next level. I have only ever used webstorage for highscores and can't work out how to adapt it for what i need it for.

    any help would be great and thanks in advance

  • if your levels are linear, you can just add a var 'level' starting at 1 and add 1 to it when you finish a level.

    then save it to webstorage - add key="level" value=level.

    if not i recommend you add a dictionary instead of pre-adding all the levels as vars (may be a lot of them) and push a key to it every time you finish a level - add key="level"&level (value doesn't matter, if you want to keep an extra state of the level you can write it in the value, i usually write down another json in the value with all my data).

    then save this dictionary to json to webstorage.

  • thanks for the reply Lof

    I did try to have one var like you said done it the same way just added 1 per win. The problem i had with that was you could just play the 1st level over and over to unlock all the other levels. but i think it might just be easier to do it that way and hope people don't work it out.

    and il have to have a look into dictionary

    Thanks again

  • so have two vars 'level' 'nextLevel', set level to the right level at the beginning of each level and then when you finish set 'nextLevel' to level+1

    or to be exact set it to max(nextLevel,level+1), so if you'll reach level 10 and go back to play level 1 it won't return to 2.

  • provokedninja did you figure it out? can someone post a capx?

  • provokedninja did you figure it out? can someone post a capx?

    Webstorage is deprecated. You should really look at using Local Storage now.

  • Webstorage is deprecated. You should really look at using Local Storage now.

    how we can save arrays in local storage

  • > Webstorage is deprecated. You should really look at using Local Storage now.

    >

    how we can save arrays in local storage

    Wouldn't that be as easy as setting the item to Array.AsJson ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yup just save it to json then load it from json.

  • OK i can save by arryay.as.Json

    but how to load it on startup

  • As explained in this tutorial:

    how to use the localstorage plugin:

    In your on start of layout add an actiont to check if local storage item exists

    add a new event to your event sheet:

    local storage on item exist:

    array load : localstorage.itemvalue

    As far as I know you don't need a step inbetween..

  • ok ok ok

    now i m getting this point

    global variable and array has same method to save

    in array

    local storage on item exist:

    array load : localstorage.itemvalue

    this is a little change

    otherwise everything is same

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)