← the guide

ASYNC SCRIPT: the reference

The company's terminals run scripts in ASYNC SCRIPT, a small strict subset of Python that the game reads and runs itself, a slice at a time.

Nothing runs outside the game. This page is the whole of it: the language, the hardware, every call, the scripts head office ships, and how

to write your own. (A player, or an AI reading this, should be able to write working scripts from it alone.)

In the game: E on a terminal opens its EDITOR. SAVE + RUN saves and starts it from the top; STOP; SAVE; TESTS runs the

script's test blocks against a copy of the base (nothing real moves); MANUAL is the short form of this page; RESTORE DEFAULT has

head office send its script back (8 credits); GRADE II/III gives the terminal more steps a tick. A company terminal with jobs has

JOB tabs: the scripts its staff run (below).


1. The language

Python, a strict subset. Blocks by indentation (4 spaces, or a tab; mixed in one block is an error). Comments start with #.

Values: None, True, False, numbers (one kind: 3, 2.5), strings ('..' or "..", escapes \n \t \\ \' \"),

f-strings (f"{x} kW", f"{n:,}" thousands, f"{x:.2f}" decimals), lists [1, 2], dicts {"a": 1}, tuples from a, b = 1, 2.

Statements: x = ..., x += / -= / *= / /=, if / elif / else, while, for x in ..., break, continue, pass,

def name(a, b=1): (closures and recursion work), return, try: / except Name as e: / finally:, raise ValueError("why"),

assert cond, "message", global name (inside a def, to change a top-level name), and test "name": blocks.

Expressions: + - * / // % **, comparisons (chains: 0 < x < 10), and or not, in, not in, is None, indexing a[0], a[-1],

slices a[1:3], calls with keywords f(x, careful=True), x if cond else y, lambda x: x + 1, list comprehensions [x * 2 for x in xs if x].

Built-in functions: print(...) / log(...) (a line on the terminal's screen), len, range, str, int, float, bool, abs,

round, min, max, sum, sorted(xs, key=..., reverse=True), list, dict, tuple, enumerate, zip, any, all, type,

isinstance, now() (game seconds since the script started), rand(), randint(a, b), and the three that make a script live:

• wait(seconds): pause; the rest of the tick goes back to the base.

• every(seconds, fn): call fn() on a schedule (0.1 s at least); keeps the script running.

• on("event", fn): call fn(data) when the base sends that event: "motion" (a camera's name) and "message" ({from, msg}).

Methods: strings upper lower strip split join startswith endswith replace find count isdigit format; lists `append extend pop insert

remove index count sort reverse copy clear; dicts get keys values items pop update`.

Not in the language, on purpose: classes, imports, with, generators, *args.

Errors are Python's, with the line: line 12: NameError: name 'gate_stauts' is not defined. Kinds: `SyntaxError NameError TypeError

ValueError ZeroDivisionError IndexError KeyError AttributeError AssertionError RuntimeError OpLimitError DeviceError`. An error stops that

terminal's script; its screen and the editor show the line. try/except catches them like Python.

How it runs: each terminal runs its script a slice at a time: a budget of steps a tick by its grade (I: 200, II: 500, III: 1200).

A loop with no wait() just uses its whole budget every tick (and does nothing else); wait, every and on are how a script shares

the time. A script that runs off its end stops, unless every or on keep it alive.

Tests: a test "name": block runs only from the TESTS button, against a copy of the base: the same calls, the same numbers, and every

call that would change something (a screen, the account, a message) goes nowhere. The script's defs and top-level settings are made first;

its main code does not run.

def ring_word(p):
    return "WORN" if p < 30 else "GOOD"

test "worn under thirty":
    assert ring_word(20) == "WORN"
    assert ring_word(80) == "GOOD", "should be good at 80"

2. The hardware (wired, powered: Space Engineers' way)

Every scripted thing is a DEVICE: a terminal, a monitor, a camera, a network switch, a money counter. A device works when it is:

1. on (E on it: switch it off or on),

2. powered: there is power on the base's bus (the grid; every device draws: terminal 0.4 kW, monitor 0.2, camera 0.1, switch 0.1,

counter 0.3; the GRID line lists "terminals, screens, cameras"), and

3. wired: on the base's network. The company's own devices are wired; rooms the company wired have a port (SECURITY OFFICE, COUNTING ROOM,

FINANCE OFFICE, CONTROL ROOM, APERTURE PLANT, HOLDING's GUARD STATION, RESEARCH OFFICE); any other room needs a NETWORK SWITCH (one a room).

A device's light: green, working; amber, not wired; dark, off or no power; red on a terminal, its script stopped on an error.

Buying and putting up: SUPPLY, TERMINALS AND SCREENS: a terminal (100 credits), a monitor (40), a camera (60), a network switch (30).

In the base, P puts the part up where you look: a monitor or a switch on a wall, a camera on a wall or the ceiling, a terminal on the

floor (it gets a stand) or on a desk. Shift+P picks which part. E on a part you put up: switch it off or on, or take it down (back

into the store). A bought camera's feed shows on any monitor a script points at it, drawn live when you are near that monitor.

The company's own: SEC-TERM and SEC-1..9 (the SECURITY OFFICE wall), CTRL-TERM and CTRL-1..3 (the CONTROL ROOM, ALPHA), FIN-TERM and

FIN-1, FIN-2 (the FINANCE OFFICE, B6), COUNT-TERM, COUNTER-1..4 and EXCHANGE (the COUNTING ROOM, B6), HOLD-TERM and HOLD-1..8 (HOLDING's

GUARD STATION, SB), RES-TERM (the RESEARCH OFFICE). Cameras: GATE ROOM, AIRLOCK, CORRIDOR, LIFT LOBBY, HOLDING, VAULT, FWD WEST, FWD EAST,

FWD INSIDE, BLOCK A, BLOCK B, GUARD STATION, LIFT CORRIDOR.

Look closer: E on a monitor's picture fills your screen with its camera (E, Esc or a step: back). You are on camera too.


3. Every call

Each call checks that the terminal it runs on is on, powered and wired (a DeviceError if not), and that what it names exists (a ValueError). A screen or camera that is broken, off or unpowered is skipped by screens.show/text/bar/clear (the terminal says [SKIPPED HOLD-8: broken ...]) and the rest of the script goes on. A script stopped by a DeviceError tries again by itself every 10 seconds.

Screens and cameras are named as on their labels ("SEC-1", "GATE ROOM"), any case.

screens

calldoes
screens.list()the monitors this terminal can reach
screens.show(screen, camera)a camera's feed on a monitor
screens.text(screen, title, lines)text on a monitor, or on a terminal's own screen (its name), up to 12 lines
screens.bar(screen, label, value, max)a bar
screens.clear(screen)NO INPUT

A monitor nothing is sending to says NO INPUT. When a terminal stops, the screens it was driving go to NO INPUT.

cams

calldoes
feed.list()what the TEAM FEED panel can show: the branch's cameras, the portal relay, teammates
feed.show(name)the panel watches that (a name from feed.list(), or "gate", "portal", "team")
feed.auto()the panel picks by what is going on
feed.now()what the panel shows now
cams.list()the cameras on the network
cams.motion(name)movement in view, 0..1 (people who moved more than a quarter metre in the last second, within 14 m and 45 degrees)
cams.status(name)"ok", "off", "no power", "no network", "gone"
on("motion", fn)fn(camera) when a camera starts seeing movement

vault, counter (the count)

calldoes
vault.cash()the account, in dollars
vault.gold(){bars, price, value}
vault.bonds(){count, value} of the bearer bonds on the shelf
vault.stacks()the vault's stacks this shift: [{id, label, flagged}]
counter.count(id, careful=False)a money counter's count of a stack. Fast: half a second, and it misses some short stacks (the same ones every time). Careful: four seconds, never wrong.
counter.flag(id, why)send a stack to the audit: True if it was short. Flagging a good one marks the count down.
counter.summary(){stacks, flagged, shift}

Some stacks are short every shift. What COUNT-TERM's script flags decides what "count the vault" pays: x0.4 counted by hand (the terminal

down), x1.2 with every short stack found; each good stack flagged takes 0.05 off.

bank

calldoes
bank.balance()the account, in dollars
bank.fee(){pct, why}: the exchange fee and what moves it
bank.market(){async, change, gold}: ASYNC's price and its last move, gold a bar
bank.ledger(n=10)the last n lines of the shift reports: [{shift, what, amount}], newest first, dollars

gate, power

calldoes
gate.status(){open, state ("OPEN", "SHUT", "DIALLING"), address, secs, cells}
gate.checklist()[{name, ok}]: the gate's checklist
gate.ring(){plating, word, worn}: the contact ring
gate.address() / gate.known()the address the ring is set to {world, depth, name}; every address on the record (AI-01's first two always)
gate.dial(depth, world=0)CONTROL ROOM terminal only: sets the ring to a known address and dials it; every check the console makes applies (cells, breaker, checklist). True if it started
gate.close()CONTROL ROOM terminal only: closes the ring (or stops it dialling); False if it was shut
power.supply() / power.load() / power.surplus()kW made, kW drawn, what is left
power.sources() / power.loads()[{name, kw, on}] / [{name, kw}]
power.generator(){fitted, on, fuel}

doors, lights

doors.list()["outer", "inner", "control entry", ...]: the gate area's doors, and every room with a lock fitted
doors.state(name)a door {name, open, stuck}; a room {name, lock, locked}
doors.open(name) / doors.close(name)SECURITY OFFICE or CONTROL ROOM terminal only. The airlock's interlock holds; a stuck door raises DeviceError. They still shut by themselves
doors.lock(room) / doors.unlock(room)SECURITY OFFICE or CONTROL ROOM only: a fitted lock to your key only, or back to the staff's badges
lights.list()[{name, room, on}]: B1's ceiling lights, L1 to L21
lights.state(name){name, room, on, out} (out: broken, a fault)
lights.on(name) / lights.off(name)SECURITY OFFICE or CONTROL ROOM only. Off stays off (saved) until a script, or you, puts it on

A call made from the wrong room raises PermissionError.

reactor, ship

reactor.status(){fitted, power, kw, rods, temp, flow, scram, alarms}: the Hale reactor on B2
reactor.target(pct) / reactor.flow(pct)RX-TERM only (the reactor desk, B2): where the rods go (the operator still eases them back if it runs hot); the coolant flow, 20 to 100
ship.status(){active, kind, left}: the gold shipment (B6)
ship.haul()a job script on "move the shipment" only: moves a pallet-load along the lane (8 s; more work from a skilled hand); the loads left, or None

staff, holding, devices, report

calldoes
staff.list()[{id, name, post, task, on}] everyone hired
staff.task(id) / staff.mood(id)what they are doing; 0..100
holding.cells()[{cell, open, held, since}] HOLDING's fourteen cells
holding.keys()True when the cell keys are on the key safe
devices.list() / devices.status(name)every device: [{name, kind, room, status}]
report.log(x)a line on this terminal's screen
report.alert(x)a toast at home (one every ten seconds a terminal)
report.line(x)a line in the shift report's memos
jobs.log()this shift's work by person: [{id, name, task, done, notes}]

fwd, net (through the gate)

calldoes
fwd.link()True while the gate is open to the forward base (AI-01 / LEVEL 0) or a relay you set down
fwd.status(){link, site, address, secs}
fwd.who()who is out there: you, your team, an expedition crew
fwd.door(){open}: the forward base's door
net.send(to, msg)to a terminal by name, "ALL", or "FWD": the forward base's desk computer (lines), through the gate. When the gate shuts it says LINK DROPPED.
net.recv()the next message for this terminal, {from, msg}, or None
on("message", fn)fn({from, msg}) as each arrives (0.2 s after it was sent)

job, lab, press (job scripts only)

calldoes
job.who(){id, name, post, skill, mood}: the person running this copy
job.task() / job.shift()the task; the shift's number
job.done(n=1, note=None)log work done (and a note for the shift report)
job.fail(why)a failure, in the notes
lab.study()(study the samples) work on the next sample: takes time (less for the skilled), returns what was found; None when the person's four samples a shift are done
press.denoms() / press.print(note, count)(print bonds) the notes; print certificates, paid from the account, a quarter of it a shift at most

4. Job scripts

Some staff tasks are done by script. The task's script is on its workplace's terminal (the JOB tabs): SEC-TERM has "watch the cameras" and

"guard the gate room", RES-TERM "study the samples", COUNT-TERM "print bonds". Everyone on the task runs their own copy, as themselves

(job.who()), while the terminal is up and their badge opens the area. What their copy logs is what the shift gets:

• watch the cameras: each job.done() is a look round every camera; thirty make the shift (the camwatch jobs on the board).

• guard the gate room: rounds, in the shift report.

• study the samples: samples studied go to RESEARCH, four a person a shift at most.

• print bonds: what press.print prints goes on the vault's shelf.

With the terminal down (off, unpowered, unwired, stopped), they work by hand: a third of the cameras, one sample, head office's old bond rule.


5. Head office's scripts (the defaults)

Each company terminal ships with one, and RESTORE DEFAULT (or the IT TECHNICIAN, an invited specialist at SUPPLY) puts it back.

• security.cams (SEC-TERM): every camera on the wall in order, SEC-1..9; a camera that sees movement goes up on SEC-1 for twelve seconds;

movement in the GATE ROOM with the gate shut is an alert, once a minute at most.

• control.checklist (CTRL-TERM): the gate's checklist on its screen every two seconds, a log line when it goes all green or something goes

red; the forward base's three cameras on CTRL-1..3; the gate's state to the forward base's desk screen every ten seconds while linked.

• finance.screens (FIN-TERM): the account, gold, bonds, ASYNC and the fee, every ten seconds.

• counting.count (COUNT-TERM): every unflagged stack, a fast count, flags the short ones it sees; a pass every twenty seconds.

Set CAREFUL = True and it finds every short stack, slower.

• holding.watch (HOLD-TERM): the blocks and the ways in on the wall, the two blocks on the desk (HOLD-2 jumps to movement), who is held

where (HOLD-7), open doors and the keys (HOLD-8).

• research.desk (RES-TERM): who is on the samples and what they have found.

• Job scripts: job.cams (a look every five seconds), job.guard (a round every thirty), job.study (sample after sample),

job.bonds (once a shift, a tenth of the account in the largest note that fits, nine at most).

Read them in the editor: they are written to be read, and to be bettered.


6. Examples

A camera of your own on a monitor of your own (a switch in the room, the camera and monitor up, a terminal):

screens.show("MON-1", "CAM-2")

The wall cycling through every camera, nine at a time:

WALL = ["SEC-1", "SEC-2", "SEC-3", "SEC-4", "SEC-5", "SEC-6", "SEC-7", "SEC-8", "SEC-9"]
page = 0

def turn():
    global page
    feeds = cams.list()
    for i, screen in enumerate(WALL):
        screens.show(screen, feeds[(page * 9 + i) % len(feeds)])
    page += 1

every(8, turn)
turn()

The power on a monitor, red when the grid is overloaded:

def paint():
    s = power.supply()
    l = power.load()
    screens.bar("MON-1", "THE GRID", l, s)
    if l > s:
        report.alert("the grid is overloaded: the cells only trickle")
every(5, paint)
paint()

A careful count only where the fast one is unsure (counting.count, better):

def check(s):
    got = counter.count(s["id"])
    if got < s["label"]:
        counter.flag(s["id"], "short (fast count)")
        return
    got = counter.count(s["id"], careful=True)
    if got < s["label"]:
        counter.flag(s["id"], "short (careful count)")

while True:
    for s in vault.stacks():
        if not s["flagged"]:
            check(s)
    wait(20)

Bonds only when ASYNC is falling (job.bonds, a policy of your own):

done_shift = -1
def run_press():
    global done_shift
    if job.shift() == done_shift:
        return
    m = bank.market()
    if m["change"] < 0:
        budget = bank.balance() * 0.15
        notes = [d for d in press.denoms() if d <= budget]
        if notes:
            d = max(notes)
            press.print(d, min(9, int(budget // d)))
            job.done(1, "ASYNC falling: into paper")
    done_shift = job.shift()
every(30, run_press)

A message between terminals:

# on SEC-TERM
def moved(cam):
    net.send("CTRL-TERM", "movement: " + cam)
on("motion", moved)

# on CTRL-TERM
def heard(m):
    log(m["from"] + " says " + m["msg"])
on("message", heard)

*The language: site/play/ascript.js (tests: tools/test_ascript.mjs). The devices and the count: site/play/devices.js. Head office's scripts

and the in-game manual: site/play/ascripts.js. The plan and what is left: docs/SCRIPTING-PLAN.md.*