How do I get webstorage to save?

Get help using Construct 2

Post » Tue Sep 02, 2014 5:35 am

ok so just trying to get a simple highscore functioning, and it does but every time i close the game the highscore resets to zero or if i dont score i get NaN
on the first layout (in reference to highscores) i have:
global highscore = 0
on start -
local key "HighScore" exists - set highscore to WebStorage.LocalValue("HighScore")
else - set local key WebStorage.LocalValue("HighScore") to 0

on the game over layout (in reference to highscores) i have:
score > WebStorage.LocalValue("HighScore") - set WebStorage.LocalValue("HighScore") to score
------------------------------------------------set highscore to score
------------------------------------------------set text to "Highscore" & highscore
score < or equal to highscore - set text to "Highscore" & highscore


just as a note when i change the "set text to "HighScore" & highscore to score"
to
"set text to "HighScore" & WebStorage.LocalValue("HighScore") to score"
the output is just HighScore
Last edited by jjc001 on Tue Sep 02, 2014 9:20 am, edited 1 time in total.
B
4
Posts: 9
Reputation: 218

Post » Tue Sep 02, 2014 7:09 am

From what i know WebStorage values are kept in strings, so try int(WebStorage.LocalValue("HighScore"))
Image
B
80
S
30
G
12
Posts: 517
Reputation: 12,713

Post » Tue Sep 02, 2014 9:19 am

that didnt fix it :/ i ran it in debug mode and when i look at the webstorage that the value for "HighScore" doesnt have a name, only a value.
B
4
Posts: 9
Reputation: 218

Post » Tue Sep 02, 2014 9:39 am

Go through this tutorial.
Read the manual. To see how to compare text/number.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Tue Sep 02, 2014 10:25 am

"set local key WebStorage.LocalValue("HighScore") to 0"

I think the problem is here, you don t want to set the local key named WebStorage.LocalValue("HighScore") but the one named "HighScore".
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Sep 02, 2014 8:54 pm

Thank you so much guys, Aphrodite u found the problem.
B
4
Posts: 9
Reputation: 218


Return to How do I....?

Who is online

Users browsing this forum: humanescape, Klarner, worm1, Yahoo [Bot] and 27 guests