How do I add high scores from multiple levels together?

0 favourites
  • 4 posts
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • 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.

  • 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 <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> 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

    Subscribe to Construct videos now

    Let me know if you need a better explanation and I'll upload a new version with comments. Hope that helps! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great. Thank you! I'll check these out over the next couple days.

  • I got it working. Your capx was very helping for me to finally understand using arrays. Thank you so much!

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