WebStorage is seen by other games from my pc

Get help using Construct 2

Post » Tue Feb 18, 2014 2:39 pm

Hi guys,
I am using WebStorage to save the high score and it working like like I want it to, but I found 2 odd things:
1. I have reused one of my game templates and used the same local WebStorage variable called "HighScore" in my newest game. The problem is that The first time I run it I saw the High Score from my previous old game. Renaming the project in my opinion should have sandbox-ed . Is there another way instead of renaming my variable since it easier to just copy the code from the template?
2. In debugger/Inspector I see WebStorage and arrays that I used in other games and not in this one.
B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Post » Tue Feb 18, 2014 2:45 pm

The Webstorage object exploits the "localStorage" javascript object. This storage is accessible from all pages/tabs in the same browser on the same domain, and have no expiration date.
This mean you should use some kind of prefix in from of all your variable to keep them from mixing between your games, if they are hosted on the same domain.

A simple way to do so is to create 2 functions in C2, a setStorage and a getStorage, that would take the key "highscore" as a parameter (in your example), and set/get in the storage using the key "application_prefix"&"highscore".
Application_prefix needs to be a constant here, for example the name of the game and an underscore.
Once you've got this, just change all the calls to the set/get you had by calls to these functions instead, and it should be all good.
B
17
S
8
G
4
Posts: 461
Reputation: 6,147

Post » Tue Feb 18, 2014 3:11 pm

@Guizmus Thanks for the explanation. Good idea of using a function with a constant variable. I will try to get Browser.Title & highscore instead of using a constant variable.
Thanks
B
78
S
21
G
23
Posts: 513
Reputation: 18,623

Post » Tue Feb 18, 2014 3:15 pm

Careful though, browser.title sometime gets modified by spywares or others on the players computer. A key dedicated for each app and stable no matter what is important, so having a constant should be less dangerous.
B
17
S
8
G
4
Posts: 461
Reputation: 6,147

Post » Tue Feb 18, 2014 4:09 pm

@Guizmus did not know that. Thanks again. I think safe is better than sorry
B
78
S
21
G
23
Posts: 513
Reputation: 18,623


Return to How do I....?

Who is online

Users browsing this forum: digitalsoapbox, RetrocadeMedia and 1 guest