What am I doing wrong with WebStorage?

Get help using Construct 2

Post » Thu Feb 26, 2015 2:57 pm

Hello, I read/watched a bunch of text/videos on the topic of webstorage and saving the highscore, but I cannot get it to work myself. I attached a screenshot of the code that I am using and to me it makes perfect sense and should work, but when I refresh the webpage of my game the high score value just goes back to 0. Could it be that the webstorage doesnt work when testing the game directly from construct 2 or am I just making an epic mistake?

Thank you
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 24
Reputation: 302

Post » Thu Feb 26, 2015 3:04 pm

Hi,

not sure, but try to cast webstorage.localValue to int..
Then you checks will be
HighScore < int(WebStorage.LocalValue())..
B
6
S
1
Posts: 45
Reputation: 509

Post » Thu Feb 26, 2015 5:36 pm

nope doesnt solve the problem, but thanks for the reply
B
6
Posts: 24
Reputation: 302

Post » Thu Feb 26, 2015 6:00 pm

localvalue("Highscore")


mind the qoutes :)
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895

Post » Thu Feb 26, 2015 6:28 pm

Still doesnt work, could it be that webstorage doesnt work in browser?
B
6
Posts: 24
Reputation: 302

Post » Thu Feb 26, 2015 6:44 pm

Post a screenshot of what you have now.
B
55
S
28
G
18
Posts: 1,520
Reputation: 25,285

Post » Thu Feb 26, 2015 6:47 pm

No in your example, you did not use qoutes in referencing the name of the variable.

You use the variable reference Highscore as the name.


for instance

variable Highscore = 1000

And you do Highscore >= webstorage.LocalValue(Highscore)


That means your doing:

Highscore >= webstorage.LocalValue("1000")


Menaing you are referencing a variable called "1000" in the webstorage, while you should be refering to its name, getting you the value of the local stored "Highscore".


And yes, web storage .... is used for storing in the web browser ....
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895

Post » Thu Feb 26, 2015 8:29 pm

i dont think so because my global variable for the highscore is "HighScore" but the localvalue is "Highscore" the S is lower case. Would that sill make it not work?
B
6
Posts: 24
Reputation: 302

Post » Thu Feb 26, 2015 10:22 pm

Jasa wrote:i dont think so because my global variable for the highscore is "HighScore" but the localvalue is "Highscore" the S is lower case. Would that sill make it not work?



I was not referring to the upper or lower case ....


In your first image, there are 3 locations where you pass the content of your Highscore variable as the name of the local variable in webstorage.
Who dares wins
B
50
S
10
G
10
Posts: 1,728
Reputation: 12,895

Post » Thu Feb 26, 2015 10:42 pm

Thank you! I was missing the """""" I solved my problem :))
B
6
Posts: 24
Reputation: 302


Return to How do I....?

Who is online

Users browsing this forum: wooowmk and 6 guests