Adding High Score with FireBase

1) Before you get started, take a look at our basic instruction for working with Woof and Firebase. Look through Google's Firebase Setup Guide and Instructions for working with the Firebase database.
2) Write your game and test it to make sure it works well without the High Score first.
3) Wrap all your game code in a function, called runGame().
Below the runGame() function, call runGame() to run the game.
Make sure that your game works as before.
4) Replace the call to runGame with the following code:

importCodeURL("", runGame)
This loads the Firebase libraries before running your game.
Make sure your game still works as before.
5) Create an account on Google Firebase and open a new project.
6) Change the Rules on the database by clicking on "Database" then "RULES", then "LEARN MORE" in the Console.

Then choose "PUBLIC" from the example rule sets.

Replace the rules for your project with the PUBLIC rules. This will allow your game code to read and write freely to the database.
7) Go to the Firebase console, choose "Add Firebase to your web app."

Firebase will generate the config code for your project.

Highlight the config code between the second set of < script> tags (starting with "// Initialize Firebase"), copy and paste it into your project.
8) Create score and highScore variables. Inside a forever loop in your game code, check to see if score is higher than highScore, and if so, write the score value to the sharedHighScore location in the database using this line of code:

9) In the initialization section of your game, setup the highScore variable to read from the database sharedHighScore location using the following code:
firebase.database().ref("sharedHighScore").on("value", function (snapshot) {
  highScore = snapshot.val();
10) Add a text label to display the high score in the game.
11) Test your game and fix any bugs. Then play your game and get the high score to see if the high score is showing properly. Enjoy!