Skip to content

Query

A radar gives you one. Query gives you everybody who fell inside a circle or a rectangle

tick 0
Query0
shapetypeteamxywh
Sensor1
=
in
Query2
shapetypeteamxywh
Sensor3
=
in
Query4
shapetypeteamxywh
Sensor5
=
in
Read6
=
Sensor7
=
in
Stop8
@counter0number
everythingnullnull
ourOwnnullnull
inBoxnullnull
firstnullnull
firstKindnullnull
query circle unit null 9 6 3 0
sensor everything @queries @size

A circle of radius three around the point 9 6 turned out to hold three units: two daggers and a flare. Their list sits in @queries.

Field What is in it
first the shape: circle or rect
second what to look for: unit, building, bullet
third a team, or null for “anybody’s”
fourth and fifth the area’s centre in tiles
sixth the radius for a circle, the width for a rectangle
seventh the height for a rectangle; a circle does not need it

A rectangle is measured from its centre: query rect unit null 9 6 4 4 is a four-by-four square centred on 9 6, not a corner at that point.

@queries is neither a number nor an object but a list. Two instructions work with it:

sensor amount @queries @size
read who @queries 0

sensor @size gives the length, read an element by index counting from zero. From then on each element is an ordinary unit or building, everything on which is read with sensor.

And that is the whole walk:

set index 0
read who @queries index
sensor health who @health
op add index index 1
jump 1 lessThan index amount

The third field is a team, and it decides who counts:

query circle unit null 9 6 3 0 # everyone: three
query circle unit @sharded 9 6 3 0 # ours only: two

Emptiness (null) means “any team”. A specific team means its units only. There is no “everyone but mine” condition here: if you want enemies specifically, take everybody and filter by @team yourself.

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.