How do I use Local Storage with multiple values?

  • I've been trying to wrap my head around the Local Storage object, but many of the tutorials only show how to save and retrieve a single value. But the asynchronous nature of this feature is the main thing throwing me for a loop -- at first I thought I had to request and retrieve values in sequence. Fortunately, last night I think it finally "clicked".

    This works, right? (I also need to check if the items exist and create them if they are missing, but I know how to do that.)

    [START GROUP]

    On start of layout:

      get item "player" get item "score" get item "sound"

    Set group "START GROUP" Deactivated

    [OPTIONS GROUP]

    On item "player" get

      System -> Set item global_player to localstorage.itemvalue

    On item "score" get

      System -> Set item global_score to localstorage.itemvalue

    On item "sound" get

      System -> Set item global_sound to localstorage.itemvalue

    I think I can even deactivate OPTIONS GROUP using "On All Gets Complete" right?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think it would be easier, ff you store all of your values in an array and load or save the array with local storage, instead of all single variables.

  • The LocalStorage documentation has a whole section suggesting using a Dictionary to deal with this.

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