- This article is about the block. For more information on the value this block holds, see Timer (value).
Timer | |
timer | |
Category | Sensing |
Type | Reporter |
The Timer block is a sensing block that reports the amount of time since the project was loaded or the timer was last reset. This block is almost always used with the Reset Timer block — usually the timer must be reset at the beginning of a project for the Timer block to hold the right value.
This block can be displayed as a Stage Monitor, though it will only display intervals of 0.1. This value can be made more precise by making a script that constantly sets a variable to the timer.
Example Uses
- Tracking time duration in One Sprite One Script Projects instead of using the Wait () Seconds block — in One Sprite One Script projects, in order to keep it Single Frame (scroll to see the whole script)
when gf clicked set [PersonX v] to (pick random (-240) to (240)) set [PersonY v] to (pick random (-180) to (180)) hide forever switch costume to (Mouse pointer v) go to x: (mouse x) y: (mouse y) stamp switch costume to (Hiding person v) go to x: (PersonX) y: (PersonY) if <<touching (mouse pointer v)?> and <mouse down?>> then show say [You found me!] for (2) seconds stop [this script v] else if <(timer) > (5)> then reset timer set [PersonX v] to (pick random (-240) to (240)) set [PersonY v] to (pick random (-180) to (180)) end end
- Showing how long a Scratcher is taking in a project (a variable can also be used for this, but it is not as accurate)
when I receive [Start the homework quiz! v]//the variable timer is showing reset timer say [Don't forget to look at the timer to see how much time you've taken up!]
- Checking if an amount of time is acceptable for advancing to another stage of the project
when I receive [new level v] reset timer when I receive [level completion v] if <(timer) < (30)> then say [You beat the level! Let's move onto the next one.] for (3) seconds broadcast (new level v) else say [You didn't finish in 30 seconds. Maybe next time.] for (3) seconds stop [all v] end
- Reacting to the length a button is held down by changing a variable faster:
when this sprite clicked //when the button is clicked reset timer change [points v] by (1) //first incrementation wait until <(timer) > (.4)> repeat until <<not <mouse down>> or <not <touching (mouse-pointer v)?>>> //since the button has been held long change [points v] by (1) //add points faster wait (.1) seconds //wait a small amount of time
Multiple Timers
Multiple timers can be simulated with variables which record the time at the beginning of the session.
when gf clicked reset timer wait (1) seconds set [timerA v] to (timer) wait (2) seconds say (join [The old timer is:] (timer)) for (1) seconds say (join [The new timer is:] ((timer) - (timerA))) for (1) seconds
Workarounds
- Main article: List of Block Workarounds
This reporter block can be replicated by using a custom made timer variable.
when gf clicked set [timestamp v] to (days since 2000) forever set [timer v] to ((86400) * ((days since 2000) - (timestamp))) end