Skip to content

Who is driving the unit

A unit obeys whoever commanded it last. Two properties tell you who that is right now

tick 0
Unit Bind0
type
Unit Control1
typexy
Sensor2
=
in
Operation3
=
@counter0number
whonullnull
ownnullnull

Two processors are looking at one poly. The upper one commands, the lower one only asks — and sees somebody else’s authority from the outside.

sensor who @unit @controller
op equal own who @this

@controller gives the block that is currently driving the unit. In the upper processor own becomes a one; in the lower it stays zero, because who there is somebody else’s processor1.

Property What it gives
@controlled a number: what kind of driver — a processor, a player, an order
@controller an object: which block exactly, or the unit itself if logic is not driving it

@controlled’s numbers are not made up; they have names:

Value Constant What it means
0 nobody: the unit lives by its own mind
1 @ctrlProcessor a processor is driving it
2 @ctrlPlayer a player is inside it
3 @ctrlCommand a player has given it an order

The properties look like two views of one thing, but each has a blind spot of its own — which is why a real check takes them together.

Hence both lines together, and in this order:

sensor ctrl @unit @controlled
jump 0 greaterThan ctrl 1 # taken by a human — leave it alone
sensor who @unit @controller
jump 0 notEqual who @this # taken by another processor — likewise
tick 0
Unit Bind0
type
Unit Control1
typexy
Sensor2
=
in
Operation3
=
@counter0number
whonullnull
ownnullnull

Here both of them command, and each drags the poly towards its own corner. Watch own in both: the one goes to whichever command ran last, and the unit dangles between two targets.

tick 0
Unit Bind0
type
Jump -> 31
if
Unit Control2
typexy
Set3
=
Sensor4
=
in
Sensor5
=
in
Operation6
=
@counter0number
orderednullnull
ctrlnullnull
whonullnull
ownnullnull

Here the order is given once, and after that the program only asks. The poly reaches the spot — and ten seconds later ctrl drops from one to zero, while who starts showing the unit itself. The processor has let it go.

Every order refreshes the term: while ucontrol is called in a loop, the authority never runs out. The moment the calls stop — six hundred ticks, and the unit returns to itself.

Two cases where ucontrol keeps quiet however often it is called:

  • a player is driving the unit. One with somebody inside is not given to logic at all;
  • the unit has an order — the kind a player hands out by selecting and clicking the map.

In both cases ubind works as usual and puts the unit into @unit — but the orders never reach it, and @controller will not say so: it goes on giving the unit itself. That leaves @controlled: two and three mean the unit is taken by a human.

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.