check webstorage

Get help using Construct 2

Post » Fri Apr 05, 2013 5:47 pm

hi, is there any way to check one value in webstorge for "Null" or "not Null"?
thanks alot.
B
4
Posts: 23
Reputation: 850

Post » Fri Apr 05, 2013 6:01 pm

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.
B
56
S
15
G
10
Posts: 910
Reputation: 11,972

Post » Fri Apr 05, 2013 8:37 pm

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.
B
4
Posts: 23
Reputation: 850

Post » Fri Apr 05, 2013 8:54 pm

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.
B
56
S
15
G
10
Posts: 910
Reputation: 11,972

Post » Fri Apr 05, 2013 11:02 pm

B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020


Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, Lancifer and 30 guests