An object in a cell
A cell stopped being an array of numbers. You put an item, a store or a unit in — and get the same thing out
A slot in memory remembers not only the value but its kind. Write a number and a number is there; write an item and an item is there, not its index.
The program puts @copper and the store itself into the cell, takes them back out and puts
them straight to work: the store that was read answers sensor, and the item that was read is
fit to be its question.
What you can put in
Section titled “What you can put in”| What | Example |
|---|---|
| a number | write 120 cell1 0 |
| an item, liquid, block or unit type | write @copper cell1 0 |
| a building | write container1 cell1 0 |
| a unit | write @unit cell1 0 |
| a string | write "done" cell1 0 |
| emptiness | write null cell1 0 |
What comes back is fit for everything the original was: a building out of a cell can be asked
with sensor, a unit out of a cell can be given an order, an item out of a cell can be named
in a question about stock.
A slot remembers one kind at a time
Section titled “A slot remembers one kind at a time”A write does not “append” a kind to the value — it replaces the slot’s contents entirely:
write @copper cell1 0write 7 cell1 0read what cell1 0what gets 7. The item is no longer there — not “item plus number”, just a number.
Hence the rule: if memory holds a list of different things, the kind has to be known in
advance. The program cannot tell from the value alone whether it is a number or a unit;
you can only check indirectly, with a strict comparison against null or by trying to ask it
for a property.
A unit in memory is a reference, not a copy
Section titled “A unit in memory is a reference, not a copy”Buildings and units go into memory as references to themselves. While they are alive everything works; when they die the reference stays and is of no use.
What it is good for in practice
Section titled “What it is good for in practice”- A queue of targets. A radar found a unit — put it into memory; another processor took it out and led it.
- A list of stores. Walk the links with
getlink, put the interesting ones into memory, and from then on work with a ready list instead of scanning everything again every iteration. - One found block for everybody. An expensive search is done once, the result sits in a cell, and the other processors simply read it.
Memory shared by two processors is the next lesson.
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.