TIPS & SCRIPTS

Things worth knowing, and scripts to copy into your machines. Try changing them: that's the point.

TIPS

  • Survival

    Light is safety

    Crawlers only spawn on dark ground away from torches, and burn in the sun. A lit, walled base is safe all night.

  • Survival

    Rubber without power

    Sticky resin from rubber trees smelts into rubber in a plain furnace, so you can make insulated cable before you have an Extractor. Crawler gel smelts into rubber too.

  • Survival

    Let items come to you

    Walk over dropped items to pick them up. They fade after five minutes. Turtles collect them with suck().

  • Editor

    Step through it

    When a script does something odd, press Step and watch each line light up. Most bugs show themselves within three steps.

  • Editor

    Read the first comments

    A new machine's editor lists its functions in comments. Delete them when you're done, or keep them as notes.

  • Editor

    Code without the crawlers

    Playing alone, creatures wait while a machine's script is open. You can turn this off in Settings.

  • Power

    Match the cable

    Copper cable carries 32 EU/t, gold 128 and glass fibre 512. Higher voltage burns lower cable and machines, so step it down with a transformer.

  • Power

    Hand crank first

    Before you have cable, a hand crank gives 160 EU a turn: two turns grind one ore.

  • Robots

    Turtles keep everything

    Pick a turtle up and it keeps its script, tools, upgrades and items. Put it down somewhere else and press Run.

  • Robots

    Far from home

    A Chunk Loader keeps a turtle working when you walk away, and a Solar Panel keeps it charged in daylight.

  • Networks

    Events save ops

    A script with @on handlers only runs when something happens, instead of every time the machine is idle. Big bases stay inside their budget this way.

  • Networks

    Antennas for robots

    A turtle can't stay on a cable, so fit it with a Modem. It joins the network of any Data Antenna within 64 blocks.

  • Networks

    Data crystals run deep

    Data crystal ore sits between layers 3 and 20, and only a diamond pickaxe gets it out. Every Age IV part needs it.

  • Fleets

    Deploy again to update

    Change your class and call deploy() again: every robot gets the new version. Robots already running the same code are left alone.

SCRIPTS TO TRY

Each one names the tier it needs. Copy it into the machine's editor and press Run.

T2 · TURRET

Base defence

A turret runs its script five times a second. nearest(ENEMY) gives back the closest hostile creature in range, or None, which an if treats as false.

Try: only fire when the target is close, using target.distance.

TURRET
# Shoot the nearest crawler in range
target = nearest(ENEMY)
if target:
    aim(target)
    fire()
T2 · DIAMOND PIPE

Sorter

A Diamond Pipe runs its script once for every item that reaches its centre. Put chests on three sides and sort your mine's output.

Try: send iron ore one way and copper ore another, using item.name.

DIAMOND PIPE
# Ores left, coal straight on, the rest right
item = pull()
if item.tag == "ore":
    push(LEFT)
elif item.name == "coal":
    push(FRONT)
else:
    push(RIGHT)
T3 · TURTLE

Tunnel and return

Digs a tunnel two blocks high, turns round and comes home. Change length to dig further.

Try: at T4, wrap it in a function that takes the length.

TURTLE
# Dig a tunnel, then come back
length = 12
for step in range(length):
    dig(FRONT)
    dig(UP)
    move(FRONT)
turn(BACK)
for step in range(length):
    move(FRONT)
stop()
T6 · STORAGE NETWORK

Stock keeper

Any machine on a storage network can count what's stored and ask the assemblers to craft more. Asking again for something already being made doesn't double the order.

Try: add more items to targets.

ANY MACHINE ON THE NETWORK
# Keep the network stocked
targets = {"torch": 64, "stick": 32}
for name in targets:
    have = net.count(name)
    if have < targets[name]:
        net.craft(name, targets[name] - have)
T7 · FLEET

A mining fleet

Name three turtles "miner", give them Modems near an antenna, and run this on any machine on the network. Every robot digs six blocks forward.

Try: give the Harvester a full() check that sends it home.

ANY MACHINE ON THE NETWORK
class Harvester(Bot):
    def __init__(self):
        self.dug = 0

    def tick(self):
        if self.dug < 6:
            self.dig(FRONT)
            self.move(FRONT)
            self.dug += 1

sent = deploy(Harvester, "miner")
print("deployed to", sent, "robots")
> deployed to 3 robots