How do I save a high score using Webstorage?

0 favourites
  • 5 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi, I have tried following multiple tutorials, but they all seem to include way to many variables or don't address all of my questions. I want to save 1 high score and replace it if the player beats it.

    https://www.scirra.com/tutorials/266/we ... nformation

    I tried this, but am unsure of what variables I need to define and what Webstorage automatically handles on it's own. It says "HighScore" but is that a text object, variable or neither?

    Thanks

  • Using web storage you just store anything to the key, so if you stored something under the key ('highScore') , you can then use the functions provided to get whatever is stored in that key, the 'key' can be anything you choose as its name.

    However, if you are looking to implement a 'high score' table that other people can view (so the scores are global if you like and everybody can see / try and beat them) , the web storage is not what you need as its limited to the person playing the game only.

    Anyways... I dont know if I have explained very well, but here are 2 tutorials that might help you, the first one is about making a high scores table using web sotrage

    https://www.scirra.com/tutorials/448/ar ... high-score

    And this second one is to do what I mentioned earlier and make a high scores table available to anybody who plays from any device.

    https://www.scirra.com/tutorials/346/on ... -php-mysql

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In my tutorial Asteroid clone in less than 100 events's score system, I show you a way to sort your score within an array before saving it to webstorage all at once.

    You can adapt the array sorting to only pick the score you are interested in and then save it as its own individual webstorage key.

  • Using web storage you just store anything to the key, so if you stored something under the key ('highScore') , you can then use the functions provided to get whatever is stored in that key, the 'key' can be anything you choose as its name.

    However, if you are looking to implement a 'high score' table that other people can view (so the scores are global if you like and everybody can see / try and beat them) , the web storage is not what you need as its limited to the person playing the game only.

    Anyways... I dont know if I have explained very well, but here are 2 tutorials that might help you, the first one is about making a high scores table using web sotrage

    https://www.scirra.com/tutorials/448/ar ... high-score

    And this second one is to do what I mentioned earlier and make a high scores table available to anybody who plays from any device.

    https://www.scirra.com/tutorials/346/on ... -php-mysql

    In my tutorial Asteroid clone in less than 100 events's score system, I show you a way to sort your score within an array before saving it to webstorage all at once.

    You can adapt the array sorting to only pick the score you are interested in and then save it as its own individual webstorage key.

    Thanks guys. I should have given more information. I want the high score to be local and only show the top score achieved by the player, but replace it when the player beats it. Thanks for the links, I will check those out and see if they work for me!

    EDIT: I followed the first tutorial and it works great! Thanks a lot!

  • if you are using database tables / php - be sure to update the code to PDO / prepared statements...

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