Step 2: Creating the Timer

Goal:


Now let’s add on to this previous code and add a loop.

This loop will be used to slowly decrease our time until it hits 0, when it does it will send a “GameOver!” message.

Steps:

  1. From Control place a repeat until block under the previous code.
  2. From Operators place a < block inside the repeat until block.
  3. From Variables place a round “Time Remaining:” block on the left side of the < block.
  4. On the right side of the < block, type in the number 1.
  5. From Control place a wait block inside the repeat until block, be sure it says 1 seconds.
  6. From Variables place a change by block and set its variable to “Time Remaining:” and the number value to -1.
  7. From Events place a broadcast block under the repeat until loop.
  8. On the broadcast block, set the message to be “GameOver!”.
  9. From Variables place a set to block under the broadcast block.
  10. Set the variable to “GameOver:” and the number value to 1.

Code: