WebStorage into Array question

Discussion and feedback on Construct 2

Post » Wed Sep 25, 2013 7:54 pm

I'm storing items the player collected (CurLevel,0 (can be 1 through 3)) in an array (named LevelComplete) at the end of the level then storing those stats into WebStorage.
WebStorage then loads that info at the start of the game.


A problem occurs when I try to check the value in the array where webstorage already posted data saved previously from another session.

When using "Compare two values" or "Array: Compare At" the events are not triggering even though they should, but using a proxy like saving the array value to a Text object and then comparing the text to the array value the events trigger normally.



Another thing is that using "less or equal" or "greater or equal" instead of "Equal to" the events go through fine as well.




I'm not sure if this is some kind of a bug with using equal to or am I just not understanding how Webstorage works correctly.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Wed Sep 25, 2013 8:40 pm

Have you tried putting quotation "" marks around the "2"?
B
51
S
20
G
10
Posts: 571
Reputation: 9,819

Post » Wed Sep 25, 2013 8:56 pm

Putting quotation marks works if the array value comes from webstorage, yes.
But then if the array was filled regularly with a number, as it originally does after first beating a level, the events do not trigger.

Now my question is shouldn't numbers stored in webstorage from an array be numbers and not a string?

EDIT: And why do "less or equal" and "greater or equal" work but "equal" doesn't when the number isn't presented as a string (no quotations)?KFC2013-09-25 21:01:40
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Thu Sep 26, 2013 12:48 pm

Basically using both "greater or equal" and "less or equal" I can get the same condition as "equal to", with the latter not triggering the events.

B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Thu Sep 26, 2013 1:27 pm

The WebStorage manual entry notes:

[quote]Note WebStorage only stores strings. If you set a key to a number like 100, when you retrieve it back it will be a string. To convert it back, use the system expression int, e.g. int(WebStorage.LocalValue("score")).[/quote]

So you're probably getting the value back from WebStorage as a string "2" rather than the number 2. Make sure you convert it back to a number when reading from WebStorage if it's supposed to be a number.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,625

Post » Thu Sep 26, 2013 2:45 pm

Many thanks.

Could you explain why less and greater are working when one of the variables is a string with a number, but equal doesn't?
B
33
S
12
G
7
Posts: 227
Reputation: 7,582


Return to Construct 2 General

Who is online

Users browsing this forum: mihirolover, whitephon and 24 guests