Skip to content

Lookup

All the game's content is numbered. Lookup turns a number into an object — and opens up walking the whole list

mediumYou need: Content constants, Loops

An item can be named with a constant — @copper, @graphite. But there are twenty constants, and writing them out one by one is tiresome. The game has numbered lists for this, and lookup fetches from them by index.

tick 0
Lookup0
= lookup
#
Lookup1
= lookup
#
Lookup2
= lookup
#
Lookup3
= lookup
#
Sensor4
=
in
Lookup5
= lookup
#
Set6
=
Set7
=
Stop8
@counter0number
firstItemnullnull
firstUnitnullnull
firstLiquidnullnull
pastEndnullnull
graphiteIdnullnull
backnullnull
itemCountnullnull
unitCountnullnull
Type How many in the game Number zero
item 20 @copper
liquid 11 @water
unit 56 @dagger
block 262 @graphite-press
lookup item item 0

The first field is which list, the second where to put it, the third the index. Past the end of a list lies emptiness, as everywhere.

Every list has a built-in variable holding its length:

set amount @itemCount

@itemCount, @liquidCount, @unitCount, @blockCount — four numbers, and they are what a walk ends on. Writing 20 instead of @itemCount is not allowed: the next update will add items, and the program will stop seeing the new ones.

An object’s index is asked of the object itself:

sensor index @graphite @id

The answer is 3 — graphite is third in the items list. Back again, lookup item back 3 returns that same graphite. This comes in handy when an item has to be stored as a number: an object does not always fit into a memory cell or a unit’s flag, but an index is an ordinary number.

tick 0
Lookup0
= lookup
#
Sensor1
=
in
Jump -> 52
if
Set3
=
Set4
=
Operation5
=
Jump -> 06
if
Print7
Print8
Print9
Print Flush10
Stop11
@counter0number
itemnullnull
indexnullnull
amountnullnull
bestnullnull
whatnullnull

The main use is walking the whole list. The program asks the store about each item in turn and remembers which there is most of: the board shows graphite: 60.

lookup item item index
sensor amount container1 item
op add index index 1
jump 0 lessThan index @itemCount

Without lookup you would have to write out twenty sensors in a row — and rewrite the program after every update to the game.

The same way finds which unit there is most of on the map, what a factory is busy with, which ore is plentiful and which block is missing from a schematic.

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.