Compatibility¶
Removed: the legacy api table¶
Lua engine 2.0.0 removed the api table. A script that still calls api.*
fails with "attempt to index global 'api' (a nil value)". Every entry has a
replacement:
| Removed call | Replacement |
|---|---|
api.localUnits() |
GetAssignedPlayer():GetPlayerObjects(); GetAssignedPlayer() is nil before a match has a local player, where api.localUnits() returned an empty table. |
api.enemyUnits() |
GetPlayerObjects() of every player GetAssignedPlayer():IsEnemyTo(player) holds for; see the example below. |
api.alliedUnits() |
GetPlayerObjects() of every player GetAssignedPlayer():IsAlliedWith(player) holds for, the assigned player included. |
api.gaiaUnits() |
GetPlayerById(0):GetPlayerObjects() |
api.unitInfo(object) |
The Object methods: GetId, GetHitpoints, GetMaxHitpoints, GetPosition, GetBuildStatus, GetOwningPlayer, GetClass, GetName. |
api.halt(object) |
UnitsStop(object), or UnitsStop(objects) for a group. |
api.moveUnits, api.moveUnitsTracked |
UnitsMove, UnitsMoveTracked |
api.commandReceipt, api.cancelCommandReceipt, api.releaseCommandReceipt |
CommandReceipt, CancelCommandReceipt, ReleaseCommandReceipt |
api.follow |
UnitsFollow |
api.guard |
UnitsGuard |
api.target |
UnitsTargetObject |
api.dropResources |
DropResources |
api.makeUnit, api.trainUnit |
TrainUnit |
api.researchTechnology |
ResearchTechnology |
api.build |
UnitsBuildStructure |
api.setGatherPoint |
SetGatherPoint |
api.ringTownBell |
RingTownBell |
api.sendBackToWork |
SendBackToWork |
api.sendAllBackToWork |
SendAllBackToWork |
api.deleteObjects |
DeleteUnit |
api.autoScout |
UnitsAutoScout |
api.seekShelter, api.seekShelterUnitsTracked |
SetUnitStanceSeekShelter, SetUnitStanceSeekShelterTracked |
api.setCombatStance |
SetUnitCombatStance |
api.setFormation |
SetUnitFormation |
api.patrol |
UnitsPatrol |
api.attackMove |
UnitsAttackMove |
api.buyCommodity |
BuyCommodity |
api.sellCommodity |
SellCommodity |
api.tributeToPlayer, api.tributeToPlayerTracked |
TributeToPlayer, TributeToPlayerTracked |
api.sendFlare |
SendFlare |
api.resign |
Resign |
api.gatherInside |
GatherInside |
api.ungarrison, api.ungarrisonTracked |
SetUnitStanceUngarrison, SetUnitStanceUngarrisonTracked |
Apart from api.halt, each command entry was the same binding as its
replacement, so the arguments and answers are unchanged. api.halt sent the
single-unit stop; UnitsStop sends the group stop.
api.enemyUnits() and api.alliedUnits() returned nil when there was no local
player or a relation could not be read. This keeps that behaviour:
local function relatedPlayerObjects(isRelated)
local me = GetAssignedPlayer()
local count, available = GetPlayerCount()
if not me or not available then
return nil
end
local objects = {}
for id = 1, count do
local player = GetPlayerById(id)
if player then
local related = isRelated(me, player)
if related == nil then
return nil
end
if related then
for _, object in ipairs(player:GetPlayerObjects()) do
objects[#objects + 1] = object
end
end
end
end
return objects
end
local enemyObjects = relatedPlayerObjects(function(me, player) return me:IsEnemyTo(player) end)
Unavailable compatibility names¶
Object:GetProductionQueueCount() now returns nil, reason when the building
or queue cannot be read. Previously those failures returned zero. Successful
reads still return the total remaining quantity, with zero for an empty queue.
Scripts should check for nil before comparing the count; using count or 0
would again hide an unavailable observation.
local count, reason = building:GetProductionQueueCount()
if count == nil then
return -- Wait for a valid observation before making production decisions.
end
if count == 0 then
-- The queue was observed empty.
end
Some names remain visible only to let older scripts load. They do not perform a useful action. Do not use them in a new script.
The API name index places these names under Unavailable
compatibility names. It also lists unavailable methods on Object and
GameOptions.
The unimplemented API reference labels each placeholder and
shows the fixed value it returns.
TrainUnit now rejects fractional
or out-of-range type IDs and counts instead of narrowing them. Type IDs must
be in 0..32767; counts must be in 1..32767. Invalid calls return false.