Create a countdown timer

This countdown timer is a great addition to any game you may wish to create in Scratch. Follow the instructions below to create it!

The first step, of course, will be to create a new project. Navigate to Scratch and click “Create” to create a new project. Delete the cat sprite that will load in by default.

Next, you will need to create your “Game Over” sprite. To do so, mouse over the button in the bottom-right corner and click “Paint.”

Click on the picture to enlarge it.

Design your “Game Over” sprite to your liking, and then click the “code” tab to code the project.

We will need a new variable called “timer” - create it by clicking “Make a Variable” in the “Variables” section.

With the sprite and variable created, the last thing to do is code the timer. Add the code above to your project after taking a look below at what each block of code does:

  • When green flag clicked: The code below this block will run every time the green flag is clicked.
  • Hide: We only want our “game over” sprite to appear after the timer runs out, so we will hide it from view for now
  • Set (timer) to (30): We will set our timer’s original value to however long we would like it to last for. For this example, we did 30 seconds, but you can make it as long or as short as you wish.
  • Repeat until <(timer) = (0)>: The code within this loop will run until our “timer” variable reaches 0
  • Wait (1) seconds: Our program will pause for 1 second before moving on
  • Change (timer) by (-1): Now that we have waited one second, we can decrease our timer. This will result in our timer decreasing by 1 every 1 second, effectively counting.
  • Show: Once the timer has reached 0, we will break out of the loop above and finally reach this block, which will show that the game is over

Source: https://www.create-learn.us