Lookup
All the game's content is numbered. Lookup turns a number into an object — and opens up walking the whole list
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.
Four lists
Section titled “Four lists”| Type | How many in the game | Number zero |
|---|---|---|
item |
20 | @copper |
liquid |
11 | @water |
unit |
56 | @dagger |
block |
262 | @graphite-press |
lookup item item 0The 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.
How many of each there are
Section titled “How many of each there are”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.
Backwards: @id
Section titled “Backwards: @id”An object’s index is asked of the object itself:
sensor index @graphite @idThe 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.
What it is really for
Section titled “What it is really for”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 indexsensor amount container1 itemop add index index 1jump 0 lessThan index @itemCountWithout 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.