check webstorage

0 favourites
  • 5 posts
  • hi, is there any way to check one value in webstorge for "Null" or "not Null"?

    thanks alot.

  • I don't think there is a built-in null function, but you could just check if the value of a key is "" or not. Since a key must be created with a value of at least "" (it can't be blank), that's as close to null as you can get.

    I.e.:

    System -> Compare two values -> First value: WebStorage.LocalValue("key"); equal to (or not equal to); second value: ""

    Otherwise, there is an action to check if a key exists or not.

  • thanks Geometrix , But when i run my game for the first time, My score is like "NaN". how can i fix this?

    i need a function like : if WebStorage.LocalValue("key")=nan then My score = 0.

    thank alot for your help.

  • Oh, okay I get it. NaN is what happens when you attempt to write a "" value from WebStorage to a number variable, which I assume is what's happened to you here.

    I can't find any way to check for NaN, so I recommend this: You first need to send a value to WebStorage before you can retrieve from it. I suggest using a global variable (CurrentScore) and only recording to WebStorage at the end of each level, and only pulling in your score from WebStorage when you load a saved game instead of trying to pull it actively right at the beginning of the game.

    A global variable will keep throughout your entire play session, so you don't need to actively write to and read from WebStorage the whole time.

    Either that, or initialise your WebStorage keys - just set them to "0" on layout start.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • <img src="https://dl.dropbox.com/u/8367729/construct/pics/webstorageKeyExists.PNG" border="0" />

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