Can't get local storage right

Post » Fri Apr 21, 2017 6:24 pm

So I'm testing out local storage, I'm trying to change it between zero and one on the press of a button and change the buttons text.

See here:
Image
Nothing seems to happen when you push the button though, so i don't know what's going on? It should set it to zero or one depending on what the value is right now, and then change the text to say if it's on or off?

Can someone point me in the right direction?
B
4
S
2
G
5
Posts: 346
Reputation: 2,417

Post » Fri Apr 21, 2017 11:45 pm

You are not using localstorage properly.

After a "Get Item" action, the LocalStorage plugin does not have a value until "On Item Get" triggers.

https://www.scirra.com/manual/188/local-storage

Local Storage is asynchronous. This means reading and writing data does not complete immediately. The actions only start the process of reading or writing a value, and the game continues to run in the interim. This ensures that slow or busy storage systems do not impact the performance of the game. When the read or write is complete, a trigger fires (On item get or On item set) which indicates either the value is available to read (with the ItemValue expression) or that the value was successfully written.


Basically, think of LocalStorage as a database server (that happens to be on the same computer as your program). You send it a request, and don't how long it will take to reply. Use the "On Item Get" condition trigger to "catch" the reply when it comes.
Mistakes were made.
B
48
S
23
G
107
Posts: 1,576
Reputation: 60,168


Return to General Discussion

Who is online

Users browsing this forum: htmlgames and 0 guests