Step 3: Checking For a High Score

Goal:


Let’s write code that will constantly be checking for a new high score.

When the player obtains a score higher than the current high score displayed on the game screen, then we want to replace the that current high score with the new score the player obtained.

Steps:

  1. Still on the Backdrop sprite, From Events, place a When I receive block and change it to “GameStart“.
  2. From Control, add a forever loop, then put an IF statement inside it.
  3. From Operators, add a > (greater than) block inside the IF statement.
  4. From Variables, add the variable “Score:” on the left side and add the variable “High Score:” on the right side.
  5. From Variables, place a set to block and change the variable to High Score:.
  6. From Variables, place a round Score: block to the right side of the set to block.

Code:


Click to replay