Skip to content

Spawn Unit

A unit appears whole and at once — with no factory, no resources and no queue

tick 0
Query0
shapetypeteamxywh
Sensor1
=
in
Jump -> 62
if
Spawn Unit3
typexyrotationteamresulteffect
Sensor4
=
in
End5
Stop6
@counter0number
amountnullnull
freshnullnull
newKindnullnull
spawn @dagger 9 5 90 @sharded fresh

A dagger appears on tile 9 5 — finished, at full health, with no factory at all. In the example the program does this until there are three of them and then stops.

Field What is in it
first the unit type: @dagger, @poly, @flare
second and third coordinates in tiles
fourth rotation in degrees: 90 is up, 0 is right
fifth the team: @sharded, @crux, @derelict
sixth where to put the created unit

The sixth field is the most useful: the unit arrives as an object and can be worked with straight away. Not with every instruction, though:

spawn @dagger 9 5 90 @sharded fresh
ubind fresh
ucontrol move 20 5 0 0 0

A world processor manages such a binding even to an enemy unit — that is its privilege.

So spawning is always limited by something:

  • count how many there already are. As in the example: query over an area, sensor @size, and spawn only if there are few;
  • do it once. A flag variable or a global flag: created, recorded, then checked;
  • by time. @time and a comparison with a deadline: a wave every half a minute.
query circle unit @sharded 9 5 5 0
sensor amount @queries @size
jump 0 greaterThanEq amount 3
spawn @dagger 9 5 90 @sharded fresh

Four lines, and the map always has exactly three daggers: one dies and another takes its place.

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.