Low-level queries and diagnostics¶
These calls expose specialised game data. They are more likely to change after a game or WololoLabs update than the everyday queries, so keep each use in a small function you can test after an update.
Wrong argument types raise a Lua error. A nil result means the value could
not be read; calls that also return a reason say so.
Fact shortcuts¶
GetFact(factId[, parameter = 0]) reads any PER fact for the
assigned player and returns value, available: 0, false when the read
failed, 0, true for a real zero. Use a Fact value for factId.
The shortcuts below each read one fact and return the value,
or nil when it can't be read.
Xs queries¶
Each Xs* call runs the game's XS function of the same name (XsGetUnitType
runs xsGetUnitType) and returns value, available. When available is
false, value is nil. Where playerId is optional, it defaults to the
assigned player.
local hitpoints, available = XsGetUnitHitpoints(unitId)
if available then LogInfo("HP", hitpoints) end
Object types¶
These read a type's definition for the assigned player; no object of the type needs to exist.
| Call | Returns |
|---|---|
GetObjectTypeName(objectType) |
The type's name, or nil when the player has no such type. |
GetObjectTypeClass(objectType) |
UnitClass (900 to 999), or nil, reason. |
GetObjectTypeAttribute(objectType, attribute[, damageClass = 0]) |
An attribute, as Object:GetAttribute reads it. 0 if unreadable. |
GetObjectTypeData(objectType, dataId) |
A PER object-data value. 0 if unreadable. |
GetIconId(kind, typeId[, playerId]) |
The icon id of a unit type (kind = "unit") or a technology ("research"), as that player's civilisation shows it, or of a resource ("resource", typeId a PlayerAttribute from FOOD to GOLD; the same for every civilisation); the player defaults to the assigned one. Unit and research kinds match GetProductionQueue entries, and the id is what batch:AddIcon draws. nil, reason (unknown-type, no-icon, icon-unreadable, player-unavailable) when there is none. |
AiCountTableHasType(playerId, objectType) |
true when the player's AI count tables have a column for the type. nil, reason if unreadable. |
Pathing and placement¶
These use the game's pathfinder and placement code.
nil means "couldn't ask", never "unreachable" or "blocked". These calls
must run on the game's own thread. Called from a script worker, they wait for
the next game frame, at most 250 ms, and return nil (with
frame-query-unavailable where a reason is returned) when the frame doesn't
run them in time: while paused, during a reload, or when more than 64 are
waiting. Each frame runs at most four of them. Cache answers and don't ask
for every candidate every update. Other reasons include layout-unavailable
(unsupported game version), player-unavailable, unknown-building-type,
invalid-position and native-fault.
GetPlacementTile flags. Terrain flag 8 is water; flags 1, 2 and
4 mark terrain the placement search won't build on. Path bits 0 and 14,
and bit 1 on land, mark blocked tiles.
CheckBuildCommand runs the game's checks in order and returns the first
that refuses:
| Stage | Meaning | Code |
|---|---|---|
build-limit |
A game-mode build limit is reached. | -1 |
builder |
This builder can't build the type. Try other builders: one passing is enough. | -1 |
gated |
The game rejects the type before placement. | -1 |
placement |
The site fails; code below. | 1 to 11 |
cost |
The player can't pay. | Resource lacked: 0 food, 1 wood, 2 gold, 3 stone |
Placement codes, shared by the three placement checks: 1 required terrain
missing, 2 invalid terrain, 3 invalid hill, 4 invalid overlay, 5 site
not visible or not explored, 6 another player's object in the way, 7 off
the map, 8 your own object in the way, 10 attacked nearby, 11 inside a
treaty zone.
CheckInfluencePlacement and CheckBuildLinePlacement run only the
placement test, with different flags from a real build, so a spot they accept
can still be refused by CheckBuildCommand.
GetWallPlanLines returns an array of { x0, y0, x1, y1, length, open }
lines (smaller x end first; open is false for water) and the step, 0 to
5; an empty array and -1 when no step qualifies. perimeter is 1 or 2.
Combat records¶
| Call | Returns |
|---|---|
GetProjectileRecord(player, projectileType) |
targetClass, attackerPlayer, timeMs of the player's latest projectile of that type; zeros when none this match. |
Player actions¶
| Call | Returns |
|---|---|
GetPlayerActionCount(player) |
Actions the player's own interface has sent since WololoLabs loaded. Sample it over time for APM. |
The human-override calls the built-in runner uses are listed with the other internal calls.
Game hooks¶
These switch on game hooks that only native code can install. A request belongs to the
script that makes it: call it from Update or Render every update, and it lapses on its
own when that script unloads, even without its Shutdown. The hooks run only during a
match. Each call returns the hook's status text; one starting Unavailable says why the
game build cannot run it.
Troubleshooting¶
Their fields can change between versions; use them while investigating, not in normal script logic.
Internal calls¶
The built-in runner and the test harness use further calls, some of them only in Debug and Dumper builds. They are not public API and can change in any update; Internal runner and harness calls lists them.
Compatibility lists the replacements for the removed api table,
and the API name index lists names that do nothing.