Time: @time, @tick, @second
Tick, second, minute and millisecond — one and the same time in four forms. Which one you pick depends on the task
Four variables, and they all show the same thing — the time since the game began:
| Variable | In what | After two seconds |
|---|---|---|
@tick |
in ticks, 60 a second | 120 |
@second |
in seconds | 2 |
@minute |
in minutes | 0.033 |
@time |
in milliseconds | 2000 |
All of them are fractional and all grow continuously: @second is not “how many whole seconds
have passed” but an honest fraction.
A timer: “once every two seconds” without wait
Section titled “A timer: “once every two seconds” without wait”jump 4 lessThan @second deadlineop add deadline @second 2op add fired fired 1endop add idle idle 1The idea is simple: the program holds a deadline — the moment it is allowed to act again —
and the rest of the time flies past. Over ten seconds fired reaches five, while several
hundred idle iterations pile up.
This is the usual way of measuring time in mlog, and it is better than
wait wherever the program has to keep working between
jobs: wait stops it completely, a deadline does not.
A clock that does not reset
Section titled “A clock that does not reset”Time runs from the start of the game, not from the start of the processor: a processor placed on
the tenth minute will see six hundred in @second, not zero.
Hence the habit of remembering the start in a variable:
jump 3 notEqual start 0set start @secondop sub elapsed @second startThat is how you count your own time: from the first iteration, not from the start of the map.
Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.