How do I add high scores from multiple levels together?

Get help using Construct 2

Post » Thu Apr 20, 2017 7:44 am

Hi. I searched for this for a few days and haven't yet found an answer. I have my game set up so it will show the high score on each level when playing the level. My localstorage is "highscore" &layoutname. I have my level layouts in a level folder and are named 1,2,3, etc. All that works.

But what I want to add is a total of the high scores on the level select screen. For example, if I get a score of 10 on level 1 and 20 on level 2, the total score will say 30. If I go back to level 1 and get a score of 11, the total score should say 31 not 41. I don't know how to load all the high scores from all the levels and then add them together to show the total score. I can't figure out what code to write.

Is there a way to get localstorage of the high scores from all the levels then add them together so I can set the text to display the total score? I would be grateful for any help on this.
B
8
S
2
Posts: 6
Reputation: 512

Post » Thu Apr 20, 2017 11:17 am

Hi @auramatt,

For this you're best off saving an array to Local Storage. I've been meaning to work out how to do this for myself for while so thanks for the push :) I've created an example here:

https://www.dropbox.com/s/2fqk21sm87kma ... .capx?dl=0

I haven't had a chance to add comments to it (in a bit of a rush) and it can probably be tidied up a bit/made more versatile, but it does the job. Try running it a few times to see how it stores the hiscores for each level and then updates them when you next run the project.

There are also a few tutorials that might help you with other ways to go about it; the second one uses the old Web Storage but you can convert it for Local:

https://www.scirra.com/tutorials/307/ar ... ers/page-3

https://www.scirra.com/tutorials/581/to ... and-arrays

https://www.youtube.com/watch?v=z_Z5rGSZnCo

Let me know if you need a better explanation and I'll upload a new version with comments. Hope that helps! :)
B
19
S
8
G
3
Posts: 429
Reputation: 3,972

Post » Thu Apr 20, 2017 1:57 pm

Great. Thank you! I'll check these out over the next couple days.
B
8
S
2
Posts: 6
Reputation: 512

Post » Sat Apr 22, 2017 7:44 pm

I got it working. Your capx was very helping for me to finally understand using arrays. Thank you so much!
B
8
S
2
Posts: 6
Reputation: 512


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish and 15 guests