How do I LocalStorage

Get help using Construct 2

Post » Sun May 31, 2015 12:42 am

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!
B
5
S
1
G
1
Posts: 9
Reputation: 1,048

Post » Sun May 31, 2015 6:39 am

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
Image Image iTunes: Match3 | Google Play: Match3
B
94
S
33
G
30
Posts: 1,099
Reputation: 27,645

Post » Sun May 31, 2015 8:30 am

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)
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: blissfulwizard, DevinMurray, RobertMKD and 15 guests