From Test-Scratch-Wiki
- This zho is about the block. For more information on the value this block holds, see Timer (value).
计时器 | |
計時器 | |
类别 | 侦测类积木 |
形狀 | 椭圆形积木 |
The Timer 积木 is a 侦测类积木 and a 椭圆形积木. The block starts at 0 when Scratch is launched and increases gradually; every second it will have increased by 1. This block is almost always used with the 计时器重置 block — usually the timer must be reset at the beginning of a 专案 for the Timer block to hold the right value.
This block can be displayed as a 舞台监控视窗.
用法示例
- Tracking time duration in 一角色一脚本类专案s instead of using the 等待 () 秒 block
— in One Sprite One Script 专案, in order to keep it single frame (scroll to see the whole script)
當 @greenflag 被點擊 變數 [PersonX v] 設為 (隨機取數 (-240) 到 (240)) 變數 [PersonY v] 設為 (隨機取數 (-180) 到 (180)) 隱藏 重複無限次 造型換成 [Mouse pointer v] 定位到 x: (滑鼠游標的 x) y: (滑鼠游標的 y) 蓋章 造型換成 [Hiding person v] 定位到 x: (PersonX) y: (PersonY) 如果 <<碰到 [mouse pointer v] ?> 且 <滑鼠鍵被按下?>> 那麼 顯示 說出 [You found me!] (2) 秒 停止 [這個程式 v] 如果 <(計時器) > (5)> 那麼 計時器重置 變數 [PersonX v] 設為 (隨機取數 (-240) 到 (240)) 變數 [PersonY v] 設為 (隨機取數 (-180) 到 (180)) end end end
- Showing how long a Scratcher is taking in a project (a 变量 can also be used for this, but it is not as accurate)
當收到訊息 [Start the homework quiz! v] // the variable timer is showing 計時器重置 說出 [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
當收到訊息 [new level v] 計時器重置 當收到訊息 [level completion v] 如果 <(計時器) < (30)> 那麼 說出 [You beat the level! Let's move onto the next one.] (3) 秒 廣播訊息 [new level v] 說出 [You didn't finish in 30 seconds. Maybe next time.] (3) 秒 停止 [全部 v] end
- Reacting to the length a button is held down by changing a variable faster:
當角色被點擊 // when the button is clicked 計時器重置 變數 [points v] 改變 (1) // first incrementation 等待直到 <(計時器) > (.4)> 重複直到 <<<滑鼠鍵被按下?> 不成立> 或 <<碰到 [滑鼠游標 v] ?> 不成立>>//since the button has been held long 變數 [points v] 改變 (1) // add points faster 等待 (.1) 秒 // wait a small amount of time end
Multiple timers
Multiple timers can be simulated with variables which record the time at the beginning of the session.
當 @greenflag 被點擊 計時器重置 等待 (1) 秒 變數 [timerA v] 設為 (計時器) 等待 (2) 秒 說出 (字串組合 [The old timer is:] 和 (計時器)) (1) 秒 說出 (字串組合 [The new timer is:] 和 ((計時器) - (timerA))) (1) 秒