- This article is about the value. For more information on the block that reports this value, see Timer (block).
The timer is extremely accurate and the value itself is not affected by lag.
reset timer: Sets the timer's value to 0.0
(timer): The stage monitor and reporter block of the value
Starting from Scratch 2.0, this block is also available:
when [timer v] > (10): This starts when timer value is greater than the input value.
How it works
The timer works in the following ways:
- Continuously counts upwards by tenths of seconds
- Cannot be paused or stopped (that would imply pausing or stopping the flow of time itself)
- Shows seconds, not minutes or larger units, even when the current value is sixty seconds or longer
- Resets only when the Green Flag is clicked or by execution of the Reset Timer block
- Continues even when the project stops running
One workaround is to increment a "timer" variable by 1/30th every frame; since Scratch runs at 30 frames per second, this can approximate an increase of 1 per second.
when gf clicked set [timer v] to  forever wait (0) secs change [timer v] by ((1) / (30))
This is, however, slightly less accurate than the timer, especially if the frame rate drops below 30 fps, and can be affected by other scripts.
Another workaround involves the Days Since 2000 block, which is itself a highly precise timer.
when gf clicked set [timestamp v] to (days since 2000) forever set [timer v] to ((86400) * ((days since 2000) - (timestamp)))
The drawback to both of these workarounds is that the actual timer continues to increase after the project has been stopped, while these scripts do not.
The timer is commonly used in projects that require a clock of some sort, such as racing projects. Other uses include:
- Using time duration in one sprite one script projects without pausing the script
- Checking how long a level took to complete
- A lag detector for a game
- A Turbo Mode detector
- A project stop detector