How do I save a high score using Webstorage?

Get help using Construct 2

Post » Tue Oct 14, 2014 11:35 am

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
B
6
S
1
Posts: 71
Reputation: 548

Post » Tue Oct 14, 2014 11:47 am

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
B
11
S
2
G
1
Posts: 68
Reputation: 777

Post » Tue Oct 14, 2014 12:04 pm

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
291
S
114
G
95
Posts: 7,290
Reputation: 70,138

Post » Wed Oct 15, 2014 12:25 pm

Neller wrote: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



Kyatric wrote: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!
Last edited by Shack on Wed Oct 15, 2014 1:17 pm, edited 1 time in total.
B
6
S
1
Posts: 71
Reputation: 548

Post » Wed Oct 15, 2014 2:45 pm

if you are using database tables / php - be sure to update the code to PDO / prepared statements...
B
11
S
2
Posts: 46
Reputation: 739


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, MaxxMunnn, Uk4dee and 18 guests