Skip to content

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

tick 0
Set0
=
Set1
=
Set2
=
Set3
=
Operation4
=
@counter0number
millisnullnull
ticksnullnull
secondsnullnull
minutesnullnull
fromTicksnullnull

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”
tick 0
Jump -> 40
if
Operation1
=
Operation2
=
End3
Operation4
=
End5
@counter0number
deadlinenullnull
firednullnull
idlenullnull
jump 4 lessThan @second deadline
op add deadline @second 2
op add fired fired 1
end
op add idle idle 1

The 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.

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 0
set start @second
op sub elapsed @second start

That 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.