Tutorial 8: robots that repair

Goal: a damaged robot or building gets its health back.

What you need

  • A robot with a builder (18 000 MT, 2 ports), a hopper and a battery_cell: a base_mk2 carries all three.
  • spare_parts (40 MT each), sold by Veles.
  • A storage_crate or warehouse. A depot and your hold's loading forms do not take spare parts, so have them delivered straight into the crate.

Steps

  1. Buy the parts into the crate:
order_place  item="spare_parts" side="buy" quantity=10 warehouse=<crate number>

On the web, choose the crate in Goods leave or arrive at.

  1. Park the robot touching the crate and load them:
def tick():
    hopper.pickup("spare_parts", 5)
  1. Save the repair script:
def tick():
    builder.repair("self")
  1. To mend something else, replace "self" with another robot's name (builder.repair("rover-7") style) or a building's number without quotes (builder.repair(12)). The target must be yours, on the robot's cell or a cell sharing a side. builder.damaged() lists your damaged robots and buildings.

Where does damage come from? Weapons and explosions. Weapons do not fire on safe fields; a power station that blows up is less polite.

What you should see

Each step gives back up to 20 health, uses 1 spare part and draws 100 W for the turn: 100 Wh from a 300 Wh cell, so three steps per full cell without sun or network. robot_get and structure_get show damage, health and max_health. A done step is an action event.

Three common mistakes

  1. No spare part in the hopper. The step fails, and it has still drawn its power.
  2. Reaching diagonally. Diagonal cells do not count for repair.
  3. Looking for a repair button. There is no tool and no web control; only a script repairs.

Next

Tutorial 9: your AI agent, safely