Timer
timer {start|due|left|elapsed|stop} {name} [time]- Sets
#TimerRes
Also searchable as: Timer · stopwatch · countdown · deadline · timeout · every n seconds · elapsed time
timer keeps as many named timers as a script needs: a world-save timer, a cast timeout, how long the script
has run. Each line answers in #TimerRes.
| Line | #TimerRes |
|---|---|
timer start {name} [time] |
Starts the timer now, or starts it again. It is due after time, or at once without one. #true. |
timer due {name} |
#true once the timer is due, #false before. A timer that was never started counts as due. |
timer left {name} |
Milliseconds until it is due; 0 once it is due, or if it was never started. |
timer elapsed {name} |
Milliseconds since it was started; N/A if it was never started. |
timer stop {name} |
Forgets it. #true if there was such a timer, #false if not. |
time is written as for wait: a number of ticks of 50 ms (20 is one second), or a
whole number of seconds followed by s (30s). A line without a name, or with another word after timer,
sets #TimerRes to N/A and does nothing else.
Examples
Section titled “Examples”Give up when something takes too long:
timer start cast 4srepeat wait 2 timer due castuntil #TargCurs = 1 || #TimerReshaltDo something every 30 seconds, in a loop that does other work meanwhile. The first time round the timer was never started, so it is due and the work runs at once:
mainloop: timer due save if #TimerRes { event sysmessage Checking for a world save timer start save 30s } wait 10goto mainloopShow how long the script has run, as h:mm:ss with str duration:
timer start runwait 3stimer elapsed runset %secs #TimerRes / 1000str duration %secsevent sysmessage Running for #StrReshaltWhat a timer is
Section titled “What a timer is”- Names are one word and ignore case:
CastandCASTare the same timer. A name may be built with., astimer start cast . %i 5sis the timercast3when%iis 3. - Timers count real time, from the moment
startruns. Pausing the script doesn’t stop them. - Nothing else moves them.
#SCntand#SCnt2can be set, and a script that doesset #SCnt 0to time something moves every deadline built on#SCnt. A timer can only be moved bytimer start. - Each script has its own timers, and a script it
calls shares them, as it shares the%variables. They are kept when the script starts over from the top (anexit, or the end of the script) and forgotten when you start it again.
Writing for EasyUO 1.5 too
Section titled “Writing for EasyUO 1.5 too”timer is new in EasyUO Reforged. In EasyUO 1.5 a line starting with timer is ignored, and #TimerRes reads
N/A. A script that must also run there builds its deadlines from #SysTime, which a
script can’t set:
set %save #SysTime + 30000mainloop: if #SysTime >= %save { event sysmessage Checking for a world save set %save #SysTime + 30000 } wait 10goto mainloopA sub or label called timer keeps working: gosub timer and goto timer find it as before.