How do I save scores?

0 favourites
From the Asset Store
Match the similar cards with each other and free all animals!
  • Hi, im developing a mobile game with 40 levels. I want to save all the best scores for each level and display them on the menu. I watched several tutorials on the internet, in every tutotrial people are using something called webstorage but in my version of construct 2 (202) instead of webstorage, i have localstorage. I tired using same the codes used in the tutorials (system-on start of layout; webstorage - set text to webstorage.localvalue("parameter")) but it isn't working for my localstorage object. Acutally the codes are different for the localstorage object.

    Please help me with this.

  • Hi,

    This is exactly what my Game Template 7 is doing <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    You can check it out here: https://www.scirra.com/store/royalty-fr ... ection-885

    It saves the highest score for each level and shows it on the levelselection screen.

    Regards

    Andreas

  • Because localstorage is a-synchronous you must first use the "get item" action and have an "on item get" event.

    New beta features aren't really well-documented untill they are implemented in the stable release.

    At that time there will be a an entry in the manual.

  • Oh tnx...i'll try that.

  • Local storage is currently in beta, and thus no tutorials/manuals etc are available yet.

    Relying on its current workings, would not be wise as it is likely to change bits and pieces before a stable release.

    Scirra perhaps you should have waited with removing the webstorage as an option till local storage has a manual and some tutorials.

    I can see a lot more of these topics popping up.

  • Ok, i just got mail from scirra regarding update of a new version. So i installed it. Now i'm not understanding how to use the new LocalStorage object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looks pretty straightforward..

    to save something use the action:

    Localstorage - set item "" to ""

    to load something use the action:

    Localstorage - get item

    to use the loaded item you will have to add an event:

    localstorage on item get - and add your action

    the action could be something like : set global variable to LocalStorage.ItemValue

  • I'll tell you my scenario. I created a global variable called 'Score' to display score on each level. I want that score value to be saved and displayed in another layout (Menu) where user can see all his/her scores of all the levels.

    As soon as the user completes a level, the score value should be recorded and showed on Menu. So that whenever user goes to that menu he/she should able see their scores.

  • Well then it should amount to something like this:

    In the level event-sheet:

    on level1 completed (this is not an official event, but I'm sure you have an event taking place at this time)

    localstorage - set item "level1Score" to Score

    in the menu event-sheet:

    on start of layout

    localstorage get item "level1score"

    localstorage on item get "level1score"

    set text = localstorage.value

  • Wow, Thanks a lot. Its working.

  • Also tell me how to replace the existing score value with higher score value.

  • I'm not sure what you mean..

  • Ok. The localstorage codes which u have provided are working, thanks for that.

    Now, whenever i'm playing a level its score is getting updated with the fresh score in the Menu i.e., for example, I played level one and my score is 4000 points and again I played the same level (Level one) for second time, my score is 3500. Now, the score 4000 is being replaced by 3500 which I made while playing second time. This shouldn't happen. The score should be replaced when the score is higher than the previous score (4000).

    I hope u understood what i'm trying to say.

  • Easiest way would be adding a global variable level1score

    on level1 completed (this is not an official event, but I'm sure you have an event taking place at this time)

    system compare variable score > level1score

    localstorage - set item "level1Score" to Score

    system set level1score = score

  • There's more than one tutorial about highscores in the tutorial section.

    I assumed you new how to do this and had a specific reason for having to use the localstorage instead of a combination of global variables and local storage.

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