Step 3: Checking for a High Score

Goal:


Let’s write code that will be constantly checking to see if the player got a high score once the game has started.

Once the game is over, the code will check if the score is greater than the current high score. If it is higher, then it will set the high score variable equal to that score, if it is lower then the rest of the code will be ignored.

Steps:

  1. Still on the Backdrop, create the shown code.
  2. From Events, add a “when I receive” block and create a new message called “GameOver!”.
  3. From Control, place an if statement.
  4. From Operators, place a > block and place it inside the if statement.
  5. From Variables, place “Points:” on the left side and place “High Score:” on the right side of the > block.
  6. From Variables place a set High Score: to and set it equal to Points:, then place it in the if statement.

Code:


Click to replay