Skip to content

A pause in seconds

Wait this many seconds — and spend not a single instruction on the waiting

wait has one field — how many seconds to wait. Fractions are allowed: wait 0.1 is six ticks, wait 2.5 is a hundred and fifty.

tick 0
Operation0
=
Wait1
@counter0number
loopsnullnull

Press “run” and watch loops: one a second, not a hundred. The program does its job once a second and keeps quiet the rest of the time.

Inside, wait is simple: while the time is not up it puts the counter back on itself and gives up the rest of the tick. On the next tick the processor hits the same line again, checks the time and gives up the tick again.

That matters: while a program is waiting it runs nothing. The @ipt budget is not spent, and the room in the tick goes to your other lines — or rather, will go to them once the wait is over.

The same one-useful-line program on a hyper processor, 60 ticks:

Tail Iterations per second
nothing 1475
wait 0 59
wait 0.5 2
wait 1 1

The difference between the first row and the second is the price of waiting: the program stops spinning for nothing. The difference between the second and the third is set by you, and that is the next lesson.

wait measures a pause in game ticks, and a tick is 1/60 of a second at normal speed. When the game is sped up or lagging, the ticks run differently, and wait 1 will not be exactly a second by the clock on the wall. For logic that is usually right: a program lives in the game’s time.

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.