Stoppable Timer

Материал из Поле цифровой дидактики

This tutorial explains how to make a stoppable timer.

Programming

Three variables are needed:

  • (custom timer) — the custom timer
  • (time stopped) — the timer to be incremented while the custom timer is paused
  • (stopped?) — a boolean that determines whether the custom timer is paused

Three broadcasts are used:

  • "reset" — resets all counters
  • "stop" — pauses the custom timer
  • "start" — starts the custom timer
when gf clicked
broadcast (reset v) //only include this if it is liked that the timer be reset upon the green flag being clicked
forever
    if <(stopped?) = [1]> then //if the timer is stopped
        set [timeStopped v] to ((timer) - (custom timer)) //the time stopped is equal to the value of the timer minus the value of the custom timer
    else //if the timer is not stopped
        set [custom timer v] to ((timer) - (time stopped)) //the custom timer's value is equal to the timer's value minus the time stopped
    end
end

when I receive [reset v] //reset all counters without disturbing "isStopped?"
reset timer
set [custom timer v] to [0]
set [time stopped v] to [0]

when I receive [stop v]
set [stopped? v] to [1] //have the timer be stopped

when I receive [start v]
set [stopped? v] to [0] //have the timer be unstopped

Example Uses

A few possible uses for a stoppable timer include:

  • A racing game
  • Timed events
  • Pausing while using a timer

ja:停止できるタイマー