How can I save and draw a high score.
Assuming you already have a variable for score, you’ll need an extra for the high score. Then, at the end of each game, compare the two.
If score > highScore then HighScore = score End
You can display the high score using the text function.
If all you need is the high score for this session, you’re done. If you want the all time high, the easiest approach is to store and read it using saveLocalData and readLocalData
Im new to this. were would i save it and what would the code look like @Mark
I cant get the high score to stay. Every time i restart it goes back to 0. @mathew
Assuming you previously saved the score with saveLocalData, then in setup, read the high score back in.
I could give you the exact code, but it’s better if you know where to find it yourself.
Press the little eye on the top row of the keyboard to get the reference. Look for Local storage in the list, at the bottom, and press that. Look for local storage, you’ll see readLocalData there. That’s what you want.
I just tried that. In my game I have objects collide and when they do the games restart would that have a factor in it not working @ignatz
as long as you store the high score when the game ends, you should be able ro read it back.
I would check it’s being stored correctly, by reading it and printing it as soon as you have stored it.