Skip to content

Writing to a cell

One line, three fields — and the value survives the iteration, the edit and the processor itself

write is read the other way round. The fields stand in the same order, and the first of them now means “what to write”:

write loops cell1 0
tick 0
Read0
=
Operation1
=
Write2
Print3
Print4
Print Flush5
Wait6
@counter0number
loopsnullnull

The counter here lives not in a variable but in memory: the iteration begins by fetching the previous value and ends by putting the new one back.

In this example — no reason: a variable would have managed on its own. The difference shows when the program gets touched.

What happened A variable A cell
an iteration passed remembers remembers
the program was edited cleared remembers
the processor was demolished and rebuilt cleared remembers
another processor looks cannot see can see

Editing the program clears the variables out of no malice: the processor rebuilds them from the text, and there is nowhere to take the old values from. A cell is a separate block, and that does not reach it.

Address What happens
2.9 a write to slot 2: the fractional part is dropped
64 on a cell nothing: the line runs, the memory does not change
-1 the same — nothing

A write overwrites whatever was at the address, in full. There is no “add to what was there” and no “write half a slot”: to increase a number in memory you read it first.

read count cell1 0
op add count count 1
write count cell1 0

Three lines instead of one is the usual price of memory. So a counter needed only inside an iteration stays in a variable, and what goes into memory is what has to outlive it.

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.