Skip to main content

Timers

timer opening daily at opensAt // every day at 18:00
timer tick every 15m // at :00, :15, :30 and :45

on timer opening
start timer lastCall at 02:30 // once, at the next 02:30
end

on building.visitorEntered
start timer quiet after 30m // once; every visitor restarts it
end

on city.powerChanged(powered)
if not powered then stop timer quiet
end

on timer tick, lastCall, quiet
decide()
end

Timers have names and belong to the instance. Every timer's name needs an on timer handler, at the script's level or in a state; a name without one is a compile error.

Declared timers​

Declared at the script's level with timer, they run as long as the instance lives, aligned to the world's clock:

  • daily at T fires every day at T;
  • every D fires whenever the world's minute is a multiple of D (1 minute to 1 day).

T and D are literals or pure expressions of properties. A declared timer's next firing is computed from its definition and the clock and is not saved: after a migration it follows the new definition with no extra code.

Started timers​

start timer fires once:

  • after D fires D from now (D greater than zero);
  • at T fires at the next time the clock reaches T.

Starting a name again replaces the earlier start. stop timer removes it and does nothing when it is not running. A started timer's due minute is saved. start or stop on a declared timer's name is a compile error.

The world's clock​

  • Durations are whole minutes. at and daily at wait for the next time the clock reaches the time, not the current minute.
  • The clock is the world's clock: in Play it stops when paused and runs faster at a higher speed.
  • When the clock moves on by several minutes, every minute is worked through in turn; no firing is skipped (The order of work).
  • There is no polling: everything is an event or a timer.