Theme aliases: — themed aliases shown in blue throughout the tables below
Language

Scripts use a Python-like syntax. Indentation is significant. Comments start with #.

ConstructExample
Assignmentx = 10
Augmented assignmentx += 5 · x -= 1 · x *= 2 · x /= 4
If / elif / elseif x > 0: / elif x == 0: / else:
While loopwhile IRON_ORE < 1000:
For loopfor i in range(5):
range()range(n) · range(a, b) · range(a, b, step)
Boolean opsand · or · not
Comparison== != < > <= >=
Arithmetic+ - * / // % **
LiteralsTrue · False · None · numbers · strings
Controlbreak · continue · pass
Commands
CommandDescription
place(type, arg, n=1, module=null) Queue n buildings of type. arg is the resource (miners) or recipe (assembly/furnace). Costs are deducted from inventory immediately. Optional 4th argument fills all module slots with the given module type (e.g. speed_module_3); modules are consumed from inventory.
craft(item, n=1) NEW Add n copies of item to the manual craft queue. Items craft one at a time in order.
research("name") Start researching a technology. Pass the display name, key, or colon-separated infinite tech key. Silently ignored if already researched.
fortify(type, n=1) NEW Add n walls or turrets to the perimeter. Deducts from inventory. Types: walls, gun, laser.
limit(type, n) NEW Set the inventory output limit for all buildings of type to n. Example: limit("am2", 200) stops all AM2s once the output item reaches 200.
limit(type, recipe, n) Set the limit for a specific building+recipe pair. Example: limit("assembly", "iron_gear", 500).
print(value, ...) Log a value to the script output panel. Multiple arguments are joined with a space.
place() — Building Types (1st argument)

Loading…

place() — Resources (2nd argument for miners)

Loading…

If the resource argument is omitted, the building's currently selected recipe/resource is used.
place() — Recipes (2nd argument for furnace / assembly / refinery / chemical plant / centrifuge / silo)

Recipes are auto-generated from data/recipes.js. Adding a new recipe there automatically creates a usable script alias. The canonical alias is the snake_case version of the recipe key. Extra shorthand aliases are listed alongside.

Loading from PLAYER_RECIPES…

place() — Modules (4th argument) NEW

The optional 4th argument fills all module slots of each placed building with the specified module. Modules are consumed from inventory at placement time. Buildings with no module slots (AM1, stone/steel furnace) ignore this argument.

Loading…

Example: place(am3, iron_gear, 5, speed_module_3) — places 5 AM3s (4 slots each) and consumes 20 Speed Module 3 from inventory.
craft() — Item Aliases NEW

craft(item, n) adds n copies to the unified manual craft queue. Items are crafted one at a time in order; ingredients are consumed when crafting begins.

Loading from PLAYER_RECIPES…

fortify() — Perimeter Defense Types NEW

fortify(type, n) transfers items from inventory to the perimeter. Will not exceed perimeter capacity.

Loading…

research() — Technology Names

Pass the exact display name or internal key. Infinite techs use the colon format.

ArgumentTechnologyNotes
"automation"AutomationPrerequisites: none
"logistics"Logistics
"steelProcessing"Steel Processing
"electricMiningDrill"Electric Mining Drill
"oilProcessing"Oil Processing
"advancedOilProcessing"Advanced Oil Processing
"plastics"Plastics
"sulfurProcessing"Sulfur Processing
"batteryTech"Battery
"lubricant"Lubricant
"flammables"Flammables
"rocketFuelTech"Rocket Fuel
"robotics"Robotics
"constructionRobots"Construction Robots
"gunTurret"Gun Turret
"laserTurretTech"Laser Turret
"nuclearPower"Nuclear Power
"kovarex"Kovarex Enrichment
"rocketSiloTech"Rocket Silo
Infinite Technologies (repeatable)
"robot:speed"Worker Robot Speed (infinite) requires Robotics
"robot:cargo"Worker Robot Cargo Size (infinite, max 3) requires Robotics
"mining:productivity"Mining Productivity (infinite) requires Electric Mining Drill
"gun:damage"Physical Projectile Damage (infinite) requires Gun Turret
"laser:damage"Laser Weapons Damage (infinite) requires Laser Turret
You can also use display names: research("Automation"), research("Nuclear Power"), etc.
Inventory Variables (read-only integers)

All item counts are floored to integers. The variable name is the camelCase item key converted to SCREAMING_SNAKE_CASE.

VariableItem
Loading from ITEMS…
Delta Variables — Production Rates (per second)

Every inventory variable has a corresponding DELTA_* version that shows the rate of change per second (updated every 1 second). Negative values mean consumption.

VariableMeaning
Loading from ITEMS…
Building Count Variables (placed buildings, read-only)

Loading…

Inventory Building Item Counts (in stock, not placed) NEW

These variables count how many of each placeable building item you have in your inventory. Use them to check whether you have buildings ready to place before calling place(). The INV_ prefix distinguishes them from placed building counts (e.g. ASSEMBLERS).

VariableDescription
Loading from BUILDING_DEFS_DOCS…
Short-name aliases (backwards compat): ELECTRIC_MINER, BURNER_MINER, STONE_FURNACE, ELEC_FURNACE, LAB_ITEM, BOILER_ITEM, STEAM_ENGINE_ITEM, SOLAR_PANEL_ITEM, ACCUMULATOR_ITEM, RADAR_ITEM, PUMPJACK_ITEM, OIL_REFINERY_ITEM, CHEM_PLANT_ITEM, CENTRIFUGE_ITEM, ROCKET_SILO_ITEM, GUN_TURRET_ITEM, LASER_TURRET_ITEM.
Module Inventory Variables NEW

Count of each module type currently in your inventory (not installed in buildings). Use these to gate place() calls that require modules. The calculator's generated scripts use these automatically when a module type is selected.

Loading…

Example: place(am3, iron_gear, 5, speed_module_3) — places 5 AM3s and fills each of their 4 module slots with Speed Module 3 (consuming 20 modules from inventory).
Power Variables (read-only)
VariableMeaning
POWER_GENTotal power generation in kW
POWER_DEMANDTotal power demand in kW
POWER_RATIOGeneration ÷ demand (1.0 = full power)
ACCUMULATOR_CHARGEStored energy in kJ
ACCUMULATOR_MAXMaximum accumulator capacity in kJ
WATERStored water (units)
STEAMStored steam (units)
Perimeter & Biter Variables NEW
VariableMeaning
BITER_WAVECurrent wave number (last wave that attacked)
BITER_TIMERSeconds elapsed since last wave (resets at 120)
PERIMETER_SIDEPerimeter side length in tiles
PERIMETER_TILESTotal perimeter tiles (4 × side length)
PERIMETER_WALLSStone walls currently placed
PERIMETER_MAX_WALLSMaximum walls the perimeter can hold
PERIMETER_GUN_TURRETSGun turrets placed
PERIMETER_LASER_TURRETSLaser turrets placed
PERIMETER_MAX_TURRETSMaximum turrets (gun + laser combined)
Queue Variables NEW
VariableMeaning
Q_lenTotal items in the manual craft queue (including active item)
Q_minersMiners / electric drills waiting in the placement queue
Persistent Memory (MEM_*) NEW

Variables whose names start with MEM_ are automatically saved to the game state and persist between script executions (including Auto runs). Use them to track state across runs.

Any MEM_* name worksMEM_A through MEM_Z, or descriptive names like MEM_LAST_WAVE or MEM_IRON_GOAL. Values are numbers or strings.
# Count how many times this script has run
MEM_RUNS = MEM_RUNS + 1
print("Run #", MEM_RUNS)

# Remember when we last needed iron
if IRON_ORE < 500:
    MEM_IRON_LOW_WAVE = BITER_WAVE
    place("miner", "iron")
Math Helpers
FunctionDescription
floor(x)Round down to integer
ceil(x)Round up to integer
round(x)Round to nearest integer
abs(x)Absolute value
min(a, b)Smaller of two values
max(a, b)Larger of two values
sqrt(x)Square root
pow(base, exp)Exponentiation
range(n)List 0 … n−1
range(a, b)List a … b−1
range(a, b, step)List with custom step
Examples

Keep coal stocked and iron miners running

# Auto script — runs every 10 seconds
if COAL < 200:
    place("miner", "coal")

if MINERS_IRON < 5 and Q_miners == 0:
    place("miner", "iron", 5 - MINERS_IRON)

Research chain automation

# Unlock automation path automatically
if RED_SCIENCE > 100:
    research("automation")
if GREEN_SCIENCE > 50:
    research("logistics")
research("robot:speed")  # queues infinite tech

Defend with walls and turrets

# Fill perimeter walls first, then add gun turrets
walls_needed = PERIMETER_MAX_WALLS - PERIMETER_WALLS
if walls_needed > 0 and STONE_WALL >= walls_needed:
    fortify("walls", walls_needed)

turrets_free = PERIMETER_MAX_TURRETS - PERIMETER_GUN_TURRETS - PERIMETER_LASER_TURRETS
if turrets_free > 0 and GUN_TURRET_ITEM > 0:
    fortify("gun", turrets_free)

Persistent crafting tracker

# Craft 10 circuits, but only if queue is empty
if Q_len == 0:
    craft("circuit", 10)
    MEM_CRAFT_RUNS = MEM_CRAFT_RUNS + 1
    print("Craft batch", MEM_CRAFT_RUNS)
else:
    print("Queue busy:", Q_len, "items")

Scale mining to demand

# If iron is dropping, add a miner
if DELTA_IRON_ORE < 0 and IRON_ORE < 2000:
    place("e_drill", "iron")
    print("Added electric miner — iron rate:", DELTA_IRON_ORE)

Power shortage response

if POWER_RATIO < 0.8:
    print("Low power!", round(POWER_RATIO * 100), "%")
    if SOLAR_PANEL_ITEM > 0:
        place("solar_panel")
    elif STEAM_ENGINE_ITEM > 0:
        place("steam_engine")