Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
What am I doing wrong here
Will either have no highscore or says 0
I don't see anything wrong. Run the game in debug mode and check the value of Highscores variable.
Also, you can get rid of "On exists" and "On get" events to make the code shorter:
On Start of Layout
LocalStorage Check if "Highscores" exist
System Wait for previous action to complete
Set Highscore to LocalStorage.ItemValue
Set HSText text to Highscore
I changed that but I'm getting NaN as a result now
Add "Local Storage Clear" action, run the project once. Then disable/remove this action, see if this will fix the error.
I think LocalStorage uses strings, not numbers, so you have to convert it to int if you're setting a number based variable to that value.
Set Highscore to int(LocalStorage.ItemValue)
Develop games in your browser. Powerful, performant & highly capable.
Local Storage can use both numbers and strings. I'm guessing it saved invalid number (NaN) once and this is causing the issue.