Adding a Local High Score in Phaser3

To add a local high score we need some way for the web browser to remember it between games — even if a player refreshes the page or even turns the browser or computer off.

📖 The word for keeping something around even between times that we run a program is called persistence and often involves storage.

But First …

Step by Step

Add an init() Method If You Don’t Have

If you don’t already have an init() method in your scene class then you should add one.

  init() {

Now add a new local variable.

  init() {
    let hscore = localStorage('hscore')