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 舞台监控视窗.


— 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))
  • 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]
  • 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

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) 秒


Cookies help us deliver our services. By using our services, you agree to our use of cookies.