Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
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.
Develop games in your browser. Powerful, performant & highly capable.
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)
Local Storage can use both numbers and strings. I'm guessing it saved invalid number (NaN) once and this is causing the issue.