Skip to content

Get Link

Links have an order, and you can walk it — without knowing in advance what is connected

easyYou need: Links and getlink, Loops

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.

tick 0
Get link0
=
Print1
Print2
Operation3
=
Jump -> 04
if
Print Flush5
Stop6
@counter0number
blocknullnull
indexnullnull

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.

getlink block index
op add index index 1
jump 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.

tick 0
Set0
=
Get link1
=
Get link2
=
Get link3
=
Get link4
=
Stop5
@counter0number
amountnullnull
firstnullnull
secondnullnull
thirdnullnull
fractionalnullnull
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.

  • 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 @type or sensor, 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 index
sensor kind block @type
jump 7 notEqual kind @container
sensor copperLeft block @copper
op add everything everything copperLeft

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.