How do I save a high score?

0 favourites
From the Asset Store
High Low is a casino game using luck and points accumulation.
  • im making a small timing game and its almost finished now i trying to add a high score for the player. Problem is that every time the player loses and restarts the game i made all global variables reset! Is there a way to save scores and exempt a global variable on the reset so that the player what his previous score was?

  • Save your scores to local storage, rather than a global variable (or save to the global variable, and save the global variable to local storage).

    On start of layout, load scores from local storage (if they exist) to global variable.

    https://www.scirra.com/manual/188/local-storage

  • Can anyone give me a guide or something im really like REALLY NEW at this i managed to make a game using global variables but this is kinda hard for me.

  • jakeedge02

    Add the LocalStorage object

    Add global variables Score=0 and HighScore=0

    Initialise your high score:

    System: On start of layout

    -> LocalStorage: Get item "HighScore"

    LocalStorage: On item "HighScore" get

    -> System: Set HighScore to int(LocalStorage.ItemValue)

    In your level end event (where you'd show the high score and have a restart button), add a sub-event:

    System: Compare Score > HighScore

    -> System: Set HighScore = Score

    -> LocalStorage: Set item "HighScore" to HighScore

  • Thanks guys i tried but but now the scores wont go up it keeps resetting back to 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are you loading the score from localstorage only on start of layout? Make sure you are not doing it every tick.

  • oh yea i think it works now but the high score is isn't showing its shows NaN is it because i put the high score on a different layout?

  • System: Set HighScore to int(LocalStorage.ItemValue)

    NaN means Not a Number. The int() part is important, as it changes a string into a number.

  • Like this? I think im doing something wrong here please note that all global variables and the local storage is in a different layout

    fav.me/db3r4ex

  • You're missing quite a few steps. Read the manual entry, follow the tutorial. Localstorage is asynchronous - that means it doesn't run in the same time as your event sheet.

    [quote:1aql7znz]For example here is a flow to read the value of the key "score":

    Use the action Get item "score"

    A moment later, On item "score" get triggers

    In this trigger, use the ItemValue expression to read the item

  • its just stays zero now

    Edit: also all the other steps are at another layout the picture is layout 3 and the other steps are at layout 1

    Edit 2: this is layout 1

    fav.me/db3rhhf

  • On the second layout, you will need to once again check if key exists, then set your variable in an "On exists" event.

  • Ugh im struggling to understand but i put the local storage check which checks if PlayerHscore exists can you please explain to this noob on what do you mean on what variables should i add? its probably something stupid that im missing or forgetting..

  • maybe its one of the events i used do you want me to send an image of all the ones i used? I just done know whats wrong the examples you linked worked fine

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