It's Sean!

UK freelance journalist, author
and writer Sean McManus

Printed from © Sean McManus.
Home > Books > Scratch Programming in Easy Steps > 10 block demos > Scratch timer example

How to make a timer in Scratch using a variable

Sean McManus, author of Scratch Programming in Easy Steps and Cool Scratch Projects in Easy Steps, shows you how to add a timer to your Scratch game

One way to add an element of challenge to even the simplest of games is to add a time limit. A countdown on-screen and a rising sound effect can help to heighten the tension. My 10-block demo below does all of this for you. You can add it to any game to add a 30 second time limit, and can adjust the time limit to any number you want.

You can put this script on any sprite or on the background. If your sprite already has other scripts on it, add the timer script as an additional script on the sprite. Don't try to combine them, otherwise you're likely to slow your game down because of the 1 second wait in the loop here.

when green flag clicked / set variable timer to 30 / repeat 30 / wait 1 secs / play note 60 minus timer for 0.1 beats / change timer by -1 / repeat ends / stop all

How my Scratch timer demo works

See it in action

You can see my Scratch timer demo below. I added a moving cat, just so you can confirm that the script stops when the timer reaches zero.

Find out more...

Find more 10 block Scratch demos here. For more information on my Scratch books and more bonus content, visit the Scratch Programming in Easy Steps and Cool Scratch Projects in Easy Steps homepages.

Books by Sean McManus

Scratch Programming in Easy Steps

Scratch Programming in Easy Steps

Raspberry Pi For Dummies

Raspberry Pi For Dummies

Learn to program with the Scratch programming language, widely used in schools and colleges.

Set up your Pi, master Linux, learn Scratch and Python, and create your own electronics projects.

Coder Academy

Coder Academy

Cool Scratch Projects in Easy Steps

Cool Scratch Projects in Easy Steps

Learn to make games and other programs in Scratch 2.0, and make a web page in HTML, with this highly interactive book for 7-10 year olds.

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

More books

Recommended articles

Stylised coloured photo of a synth

Discover my music and home recording articles

Interested in starting home recording? Follow me as I start recording, using instruments such as the Novation MiniNova and Korg Kaossilator, and share my synth and sample-based music online.

Scratch cat and rainbow circle

10-block demos for Scratch programming

Lots of people of all ages are learning to program with Scratch. Discover some useful tricks and techniques in my 10-block Scratch demos, including special effects you can drop into your games.

Paper Raspberry Pi case

Download free book chapters and more!

Download a free case for your Raspberry Pi, and free chapters from my books about the Raspberry Pi, Scratch, web design and more!

©Sean McManus.