Skip to content

Binding by type

One ubind, one unit. The next one gives another, and so on round the circle until they run out

ubind @poly

One line, and @unit holds a poly — one of those flying about the map. Every program about units starts here: while @unit is empty there is nobody to command.

tick 0
Unit Bind0
type
Sensor1
=
in
Sensor2
=
in
Sensor3
=
in
Sensor4
=
in
@counter0number
xnullnull
ynullnull
healthnullnull
kindnullnull

A bound unit is an ordinary object: sensor asks it for coordinates, health and type exactly as it would a building.

tick 0
Unit Bind0
type
Set1
=
Unit Bind2
type
Set3
=
Unit Bind4
type
Set5
=
Unit Bind6
type
Set7
=
Stop8
@counter0number
firstnullnull
secondnullnull
thirdnullnull
fourthnullnull

There are three polys on the map, and the program binds four times in a row. first, second and third get different units, and fourth turns out to be the same as first: the list closed the circle.

ubind does not “take some unit”, it walks a list. The processor has a counter — one per unit type — and every binding moves it on by one.

That is where the main technique for working with a squad comes from: one iteration, one unit. The program binds, gives an order and ends the iteration; on the next one it gets the next unit, and so the whole squad gets its turn.

ubind @poly
ucontrol move 20 30 0 0 0

Two lines with no loop at all drive every poly on the map — simply one at a time.

tick 0
Unit Bind0
type
Set1
=
Sensor2
=
in
Stop3
@counter0number
emptynullnull
healthnullnull

There are no flares on the map, and ubind @flare puts emptiness into @unit. There is no error: neither in the game nor in the example does the program stop.

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.