0 Favourites

Can't get local storage right

  • 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:

    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?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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

    [quote:2x421knt]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.

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