How do I use Local Storage with multiple values?

Get help using Construct 2

Post » Wed Jan 27, 2016 12:54 pm

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?
B
11
S
3
Posts: 78
Reputation: 852

Post » Wed Jan 27, 2016 1:27 pm

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.
B
24
S
3
G
1
Posts: 423
Reputation: 2,109

Post » Wed Jan 27, 2016 1:54 pm

The LocalStorage documentation has a whole section suggesting using a Dictionary to deal with this.
ImageImageImage
B
71
S
20
G
192
Posts: 3,535
Reputation: 109,344


Return to How do I....?

Who is online

Users browsing this forum: tetuan and 11 guests