How To Create A Timer In Scratch
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.
How my Scratch timer demo works
- You create a variable called timer. You need this to be able to show the countdown on the screen. I set the timer value to 30. You can make it shorter or longer.
- The loop waits one second and subtracts 1 from the timer value. The number of times the loop repeats is decided by the initial value of the timer.
- Each time around the loop, it plays a sound effect. The note is 60-timer, which means it gets higher each time around the loop.
- When the time runs out, the stop all block is used to end the game. All the scripts on all the sprites are stopped by this.
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.
Credits
© Sean McManus. All rights reserved.
Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!
Discover my latest books

100 Top Tips: Microsoft Excel
Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.
- More
Scratch Programming IES
This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.
- More
Mission Python
Code a space adventure game in this Python programming book published by No Starch Press.
- More
Cool Scratch Projects in Easy Steps
Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!
- More
Raspberry Pi For Dummies
Set up your Raspberry Pi, then learn how to use the Linux command line, Scratch, Python, Sonic Pi, Minecraft and electronics projects with it.
- More
Earworm
In this entertaining techno-thriller for adults, Sean McManus takes a slice through the music industry: from the boardroom to the stage; from the studio to the record fair.
- More
Scratch and Raspberry Pi resources

Sean's Scratch Resources
Tips, tutorials and free book chapters for Scratch, a coding language widely used in schools.
- More

Sean's Raspberry Pi Resources
Tutorials and guides for the Raspberry Pi, a budget computer perfect for learning to program.
- More
How To Create A Timer In Scratch
Source: https://www.sean.co.uk/books/scratch-programming-in-easy-steps/scratch-timer-demo.shtm
Posted by: hovisherivink44.blogspot.com
0 Response to "How To Create A Timer In Scratch"
Post a Comment