The memory cell
A processor's memory dies with every edit to the program. A cell remembers — and you fetch from it by slot number
A processor’s variables are its own business: another processor cannot see them, and editing
the program clears them. Shared, long-lived memory lives on the map as a separate block:
a memory cell and a memory bank. read fetches a value out of it by slot number.
The cell on this map arrived already filled: its contents are part of the save, not created fresh at start-up. The program fetches three numbers from it and prints two of them to a message block.
The line reads as “variable = where the address points”
Section titled “The line reads as “variable = where the address points””| Field | What is in it |
|---|---|
| first | where to put what was read |
| second | what we read from — here a memory cell or bank, but it can be other things |
| third | the address: a slot number, counting from zero |
read stock cell1 0A cell has 64 slots, a memory bank 512. sensor can ask the memory itself:
sensor slots cell1 @memoryCapacityThe address is truncated, and past the end lies emptiness
Section titled “The address is truncated, and past the end lies emptiness”Both rules are visible here at once:
read fractional cell1 1.9fetches slot 1, not 2: the fractional part of an address is dropped, not rounded.1.9and1.0are the same address;read pastEnd cell1 64givesnull. There are 64 slots, numbered zero to 63, and there is no sixty-fourth — but there is no error either: the variable is simply assigned emptiness. A negative address does the same;read blank cell1 7gives0: the slot exists, it is inside the cell, and it holds a zero.
A loop over memory
Section titled “A loop over memory”Walking the whole memory is an everyday thing, and the bound for it is better asked for than written as a number:
sensor slots cell1 @memoryCapacityset address 0read value cell1 addressop add sum sum valueop add address address 1jump 2 lessThan address slotsWith 64 written instead of slots, the program breaks silently the day the cell is replaced
with a memory bank: it walks the first 64 slots out of 512 and decides the rest is empty.
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.