Docs Reference

Receipts and reason codes

Every command's receipt carries a status code and a reason code. They're how bots and agents correct themselves, turning “why didn't it work?” into a machine-readable number.

r = g.train(barracks, "hfoo")
bool(r)        # False
r.status       # 1              -> rejected
r.verdict      # 3              -> not enough food
r.reason       # 'rejected(人口不够)'  (SDK output: "rejected (not enough food)")
r.exec_us      # microseconds this command took on the game thread

if r: is equivalent to r.status == 0 (the engine accepted it).

Status codes: status

CodeNameMeaningCommon causes
0acceptedThe engine accepted it— (but accepted ≠ done; see below)
1rejectedRejected by the engineSee verdict
2bad_unitThe unit doesn’t exist or its handle doesn’t matchThe unit is already dead; you used a stale unit object
3not_ownerNot your unitCommanding someone else’s unit as a player
4faultException during execution (caught by the runtime; it won’t take down the game)Please report it with steps to reproduce
5bad_argsBad argumentsWrong coordinates, slot index or four-character code
6unsupportedNot supportedThis runtime version doesn’t have that capability
7bad_targetInvalid targetThe target is gone; wrong target type
8forbiddenNot allowed for the lane’s roleIssuing commands as an observer
97cancelledAn exception was raised inside a batch block, so nothing in the batch was sentCode inside a with g.batch(): block raised an error
98heldThe unit is held by a higher-priority layer, so the command wasn’t sentThe reference brain’s reflex layer or a manual command from the console is holding the unit
99timeoutTimed outThe deadline passed while the game was paused or lagging (expired commands are never executed)

Reason codes: verdict

When a command is rejected, the runtime explains why using the engine’s own feasibility check. You can also ask before issuing the command: g.can_do(unit, code) returns the same codes.

CodeMeaningWhat to do
0 / 220OK—
3Not enough foodBuild food structures; watch g.production(b).blocked to catch it early
8Not enough goldWait for gold; check g.can_afford(code) before issuing
9Not enough lumberPut more workers on lumber
32Training queue full (7 slots)Queue only 1 at a time: queue the next when g.queue(b) is empty
183Missing prerequisite tech / buildingBuild the prerequisite first, or tier up
185Building is busyThe altar is reviving a hero; the town hall can’t upgrade while its queue isn’t empty
221Not available / under construction / upgrading / already existsThe hero already exists (use revive if it’s dead); this shop doesn’t sell that
89Shop not stocked yetAt game start, items become available at the stock time in the item table; a newly built shop starts counting from the moment it’s finished
1001Target not visibleThe target is in fog of war or the black mask; attack_move to its position

Accepted ≠ done

A receipt only tells you that the engine accepted the command, and it’s read back in the same frame. It can’t account for what happens afterward:

CommandCan still fail after being acceptedHow to confirm
BuildA spot in a forest is accepted immediately too; it fails when the worker gets thereUse build_near (it tracks whether the foundation appears), or wait for production.done
CastInterrupted, out of manaOn the next tick, check whether g.cooldown(u, ability) has started
TrainQueued, but never starts because there’s not enough foodg.production(b).blocked
Move / attackOverridden by other logic (or a higher-priority layer)g.current_target(u), g.order_of(u)

Query APIs

These APIs don’t issue orders; they only ask the engine. The result is also placed in the receipt’s value (the SDK returns the value directly):

APIReturns
g.can_do(u, code) / g.can_do_many([(u, code), ...])The reason codes in the table above
g.tech(code, player=None) / g.tech_many([...])Research level / number of completed buildings (upgrade chain included)
g.visible(x, y)Whether this point is visible to us
g.gold_left(mine)How much gold is left in a mine
g.enemy_ai_plan(enemy_unit)Where the computer opponent’s captain plans to lead its troops (computer AI only)