How do I LocalStorage

0 favourites
  • 3 posts
  • I need to make the switch from WebStorage to LocalStorage and I'm just not sure how to do it after reading the manual entry and looking at few topics on the forums. An example of what I'm struggling with -

    My webstorage key would be "RecordLevel1"

    Now when I wanted to display this in a textbox I would put Set text to - (WebStorage.LocalValue("RecordLevel1"))

    and with the local storage I'm just not sure how to do it, does it have to be a global variable? any help would be much appreciated!

  • Hi,

    I faced the same problem. I made a function on the start checking if the LocalStorage Item exists. If not, I also check if my WebStorage key exists.

    If so, I'll transfer the content of the WebStorage to the LocalStorage and then I'll clear the WebStorage.

    This function will transfer the content (your savegame or progress) into the LocalStorage.

    Also I wrote a tutorial for LocalStorage here: https://www.scirra.com/tutorials/1461/h ... age-plugin

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The thing about LocalStorage is its asynchronous. You can't just do what you'd normally do, read and write data on demand.

    Local Storage is a bit like interrogating a rather slow person on the other end of the phone e.g. to get (say) a high score

    1) Action "Check Item" (Ask it if the high score exists) by key (e.g. "myGameHighScore")

    2a) On event "On Item Missing" (No), set the default high score

    or

    2b) On event "On Item Exists" (Yes), then action "Get Item" (ask what the value of "myGameHighScore" is)

    3) If you asked "Get Item" On event "On Item Get" (Here it is) you can retrieve the actual value (from ItemValue member)

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