WebStorage is seen by other games from my pc

0 favourites
  • 5 posts
From the Asset Store
A space themed game with high quality 2D graphics and addictive music that provide hours of fun
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

  • 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.

  • Guizmus did not know that. Thanks again. I think safe is better than sorry

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)