Skip to content

A neighbour's variables

A cell for exchanging values isn't always needed — but the shortcut is paid for with a variable that changes with no trace in the program

Reading a neighbour’s variable is already covered. write works the same way round: the address is a variable’s name, and the value goes straight into it.

write 1 processor1 "needed"
tick 0
Write0
Wait1
@counter0number

The lower processor — the one whose program is shown — sets the upper one’s needed to one once a second. The upper one waits for that flag, does the work and clears it back to zero itself. There is no cell between them.

Allowed Not allowed
writing into a neighbour’s existing variable creating a new variable on a neighbour
putting a number or an object into it overwriting a constant: @pi, @copper and the rest
writing to yourself through @this an ordinary processor writing into a world one

A new variable is not created silently: if the name has a typo, the write simply does not happen. The neighbour has needed and we write into needeb — and nothing happens for anybody.

The rule: write to yourself, read from others

Section titled “The rule: write to yourself, read from others”

The exception is a short command, as in the example: one processor raises a flag, the other sees it and clears it itself. That works because the variable’s owner stays in charge: it decides when to lower the flag, and an outsider can only raise it.

A neighbour’s variable A cell
needs a block on the map no yes
survives an edit to the program no yes
visible to a third processor only through that same neighbour to everyone linked
how many values as many as there are variables 64 or 512

The main difference is the second row: an edit to the program clears the variables, and the neighbour starts reading zeroes that same second. For a “do it now” flag that does not matter; for accumulated data it decides everything.

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.