SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

9.05 Adding a timer

Let’s add a timer, so that the player has to score as many goals as they can in 30 seconds.

Make a new variable called timer.

  • Click on Variables in the Code tab, then click on Make a Variable.Variable blocks
  • Type in the name of your variable. You can choose whether you would like your variable to be available to all sprites, or to only this sprite. Press OK.Create variable
  • Once you have created the variable, it will be displayed on the Stage, or you can untick the variable in the Scripts tab to hide it.Variable on the stage

Click on your stage, and add this code to set the timer to 30 at the start of the game.

stage sprite

Next, you’ll need to add a repeat until block, so that the timer can run until it gets to 0.

stage sprite

Reduce your timer by 1 every second until it reaches 0.

stage sprite

Once the timer has reached 0, you should play the 'whistle' sound and then stop the game.

stage sprite

Click the green flag to test your code. Your timer should start at 30, and end at 0.

screenshot

You can change your timer to start at 10 if you don’t want to wait for 30 seconds!

You only have the chance to score 1 goal! To have more than 1 chance, add a forever block around your football code. You can also add a wait block between attempts.

football sprite
×
×

Cart