Get Link
Links have an order, and you can walk it — without knowing in advance what is connected
A link can be named — cell1, duo1 — or it can be taken by index. The index is the order
of connecting: the first connected block is number zero, the second number one, and so on.
The program walks every link and prints what it found: container memory-cell message.
It does not know the blocks’ names, and it does not have to.
@links — how many there are
Section titled “@links — how many there are”getlink block indexop add index index 1jump 0 lessThan index @links@links is a built-in variable of the processor: the number of connected blocks. That is what
ends the loop, not a number: connect one more block and the program sees it by itself.
Past the last link lies emptiness
Section titled “Past the last link lies emptiness”| Index | What comes back |
|---|---|
| 0 and 1 | the connected blocks |
| 2 with two links | null |
1.9 |
link number 1: the fractional part is dropped |
There is no error past the end — as with memory, the answer is emptiness.
Why walk the links
Section titled “Why walk the links”- One program for different bases. Connect six drills instead of three and the loop walks six.
- Finding the block you want. Walk the links, ask
@typeorsensor, find the one you were after. - Going over blocks of one kind. Switch off every turret, poll every store, add up the copper across all containers.
getlink block indexsensor kind block @typejump 7 notEqual kind @containersensor copperLeft block @copperop add everything everything copperLeftUnofficial 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.