Unit¶
-
class
BWAPI.Unit¶ The Unit class is used to get information about individual units as well as issue orders to units.
Every Unit in the game is either accessible or inaccessible. To determine if an AI can access a particular unit, BWAPI checks to see if
BWAPI.Flag.CompleteMapInformationis enabled. So there are two cases to consider - either the flag is enabled, or it is disabled:If
BWAPI.Flag.CompleteMapInformationis disabled, then a unit is accessible if and only if it is visible. IfBWAPI.Flag.CompleteMapInformationis enabled, then all units that exist in the game are accessible, andUnit.exists()is accurate for all units. SimilarlyBWAPI.onUnitDestroy()messages are generated for all units that get destroyed, not just visible ones.Note
Some properties of visible enemy units will not be made available to the AI (such as the contents of visible enemy dropships). If a unit is not visible,
Unit.exists()will returnfalse, regardless of whether or not the unit exists. This is because absolutely no state information on invisible enemy units is made available to the AI. To determine if an enemy unit has been destroyed, the AI must watch forBWAPI.onUnitDestroy()messages from BWAPI, which is only called for visible units which get destroyed.If a Unit is not accessible, then only the
getInitial*functions will be available to the AI. However for units that were owned by the player,Unit.getPlayer()andUnit.getType()will continue to work for units that have been destroyed.Constructors
This class is not constructable through Lua.
Member Variables
-
clientInfo¶ A Lua table that can be used to store arbitrary data associated with the current object.
Example usage¶obj.clientInfo["test"] = 5 print(obj.clientInfo["test"]) -- prints "5"
Member Functions
-
getID() → id¶ Retrieves a unique identifier for this unit.
Returns: An integer containing the unit’s identifier. Return type: number See also
-
exists() → exists¶ Checks if the Unit exists in the view of the BWAPI player.
This is used primarily to check if BWAPI has access to a specific unit, or if the unit is alive. This function is more general and would be synonymous to an isAlive function if such a function were necessary.
In the event that this function returns
false, there are two cases to consider:- You own the unit. This means the unit is dead.
- Another player owns the unit. This could either mean that you don’t have access to the unit or that the unit has died. You can specifically identify dead units by polling onUnitDestroy.
Returns: trueif the unit exists on the map and is visible according to BWAPI orfalseif the unit is not accessible or the unit is dead.Return type: boolean See also
-
getReplayID() → id¶ Retrieves the unit identifier for this unit as seen in replay data.
Note
This is only available if
BWAPI.Flag.CompleteMapInformationis enabled.Returns: An integer containing the replay unit identifier. See also
-
getPlayer() → player¶ Retrieves the player that owns this unit.
Returns: The owning PlayerorGame.neutral()if the unit is a neutral unit or inaccessible.Return type: BWAPI.Player
-
getType() → type¶ Retrieves the unit’s type.
Returns: A UnitTyperepresenting the unit’s type orUnknownif this unit is inaccessible or cannot be determined.Return type: BWAPI.UnitTypeSee also
-
getPosition() → position¶ Retrieves the unit’s position from the upper left corner of the map in pixels.
The position returned is roughly the center if the unit.
Returns: Position object representing the unit’s current position or Unknownif this unit is inaccessible.Return type: BWAPI.PositionNote
The unit bounds are defined as this value plus/minus the values of
UnitType.dimensionLeft(),UnitType.dimensionUp(),UnitType.dimensionRight(), andUnitType.dimensionDown(), which is conveniently expressed ingetLeft(),getTop(),getRight(), andgetBottom()respectively.See also
getTilePosition(),getInitialPosition(),getLeft(),getTop()
-
getTilePosition() → tilePosition¶ Retrieves the unit’s build position from the upper left corner of the map in tiles.
Returns: TilePosition object representing the unit’s current tile position or Unknownif this unit is inaccessible.Return type: BWAPI.TilePositionNote
This tile position is the tile that is at the top left corner of the structure.
See also
-
getAngle() → angle¶ Retrieves the unit’s facing direction in radians.
Note
A value of 0.0 means the unit is facing east.
Returns: A double with the angle measure in radians. Return type: number
-
getVelocityX() → velocityX¶ Retrieves the x component of the unit’s velocity, measured in pixels per frame.
Returns: A double that represents the velocity’s x component. Return type: number See also
-
getVelocityY() → velocityY¶ Retrieves the y component of the unit’s velocity, measured in pixels per frame.
Returns: A double that represents the velocity’s y component. Return type: number See also
-
getRegion() → region¶ Retrieves the Region that the center of the unit is in.
Returns: The Regionobject that contains this unit ornilif the unit is inaccessible.Return type: RegionExample¶local Broodwar = BWAPI.Broodwar local myUnits = Broodwar:self():getUnits() for u in myUnits:iterator() do if u:isFlying() and u:isUnderAttack() then -- implies exists and isCompleted local r = u:getRegion() if r then u:move(r:getClosestInaccessibleRegion()) -- Retreat to inaccessible region end end end
Note
If this function returns a successful state, then the following functions will also return a successful state:
exists()
-
getLeft() → left¶ Retrieves the X coordinate of the unit’s left boundary, measured in pixels from the left side of the map.
Returns: An integer representing the position of the left side of the unit. Return type: number See also
-
getTop() → top¶ Retrieves the Y coordinate of the unit’s top boundary, measured in pixels from the top of the map.
Returns: An integer representing the position of the top side of the unit. Return type: number See also
-
getRight() → right¶ Retrieves the X coordinate of the unit’s right boundary, measured in pixels from the left side of the map.
Returns: An integer representing the position of the right side of the unit. Return type: number See also
-
getBottom() → bottom¶ Retrieves the Y coordinate of the unit’s bottom boundary, measured in pixels from the top of the map.
Returns: An integer representing the position of the bottom side of the unit. Return type: number See also
-
getHitPoints() → hp¶ Retrieves the unit’s current Hit Points (HP) as seen in the game.
Returns: An integer representing the amount of hit points a unit currently has. Return type: number Note
In Starcraft, a unit usually dies when its HP reaches 0. It is possible however, to have abnormal HP values in the Use Map Settings game type and as the result of a hack over Battle.net. Such values include units that have 0 HP (can’t be killed conventionally) or even negative HP (death in one hit).
-
getShields() → shields¶ Retrieves the unit’s current Shield Points (Shields) as seen in the game.
Returns: An integer representing the amount of shield points a unit currently has. Return type: number See also
-
getEnergy() → energy¶ Retrieves the unit’s current Energy Points (Energy) as seen in the game.
Returns: An integer representing the amount of energy points a unit currently has. Return type: number Note
Energy is required in order for units to use abilities.
See also
-
getResources() → resources¶ Retrieves the resource amount from a resource container, such as a Mineral Field and Vespene Geyser.
If the unit is inaccessible, then the last known resource amount is returned.
Returns: An integer representing the last known amount of resources remaining in this resource. Return type: number See also
-
getResourceGroup() → int¶ Retrieves a grouping index from a resource container.
Other resource containers of the same value are considered part of one expansion location (group of resources that are close together).
Note
This grouping method is explicitly determined by Starcraft itself and is used only by the internal AI.
Returns: An integer with an identifier between 0 and 250 that determine which resources are grouped together to form an expansion.
-
getDistance(target) → distance¶ Retrieves the distance between this unit and a target.
Note
Distance is calculated from the edge of this unit, using Starcraft’s own distance algorithm. Ignores collisions.
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit. If it is a unit, then it will calculate the distance to the edge of the target unit.Returns: An integer representation of the number of pixels between this unit and the target.Return type: number
-
hasPath(target) → hasPath¶ Using data provided by Starcraft, checks if there is a path available from this unit to the given target.
Note
This function only takes into account the terrain data, and does not include buildings when determining if a path is available. However, the complexity of this function is constant ( O(1) ), and no extensive calculations are necessary.
Note
If the current unit is an air unit, then this function will always return true.
Note
If the unit somehow gets stuck in unwalkable terrain, then this function may still return true if one of the unit’s corners is on walkable terrain (i.e. if the unit is expected to return to the walkable terrain).
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit. A Position or a Unit that is used to determine if this unit has a path to the target.Returns: trueif there is a path between this unit and the target orfalseif the target is on a different piece of land than this one (such as an island).Return type: boolean
-
getLastCommandFrame() → frameNum¶ Retrieves the frame number that sent the last successful command.
Note
This value is comparable to
Game.getFrameCount().Returns: The frame number that sent the last successfully processed command to BWAPI. Return type: number See also
-
getLastCommand() → command¶ Retrieves the last successful command that was sent to BWAPI.
Returns: The last command that was processed. Return type: UnitCommandSee also
-
getLastAttackingPlayer() → player¶ Retrieves the Player that last attacked this unit.
Returns: Player that last attacked this unit or nilif this unit was not attacked.Return type: PlayerNote
If this function returns a successful state, then the following function calls will also return a successful state: exists()
-
getInitialType() → type¶ Retrieves the initial type of the unit.
This is the type that the unit starts as in the beginning of the game. This is used to access the types of static neutral units such as mineral fields when they are not visible.
Returns: UnitTypeof this unit as it was when it was created orUnknownif this unit was not a static neutral unit in the beginning of the game.Return type: UnitType
-
getInitialPosition() → position¶ Retrieves the initial position of this unit.
This is the position that the unit starts at in the beginning of the game. This is used to access the positions of static neutral units such as mineral fields when they are not visible.
Returns: Position indicating the unit’s initial position when it was created or Unknownif this unit was not a static neutral unit in the beginning of the game.Return type: Position
-
getInitialTilePosition() → tilePosition¶ Retrieves the initial build tile position of this unit.
This is the tile position that the unit starts at in the beginning of the game. This is used to access the tile positions of static neutral units such as mineral fields when they are not visible. The build tile position corresponds to the upper left corner of the unit.
Returns: TilePosition indicating the unit’s initial tile position when it was created or Unknownif this unit was not a static neutral unit in the beginning of the game.Return type: TilePosition
-
getInitialHitPoints() → hp¶ Retrieves the amount of hit points that this unit started off with at the beginning of the game.
The unit must be neutral.
Returns: Number of hit points that this unit started with or 0if this unit was not a neutral unit at the beginning of the game.Return type: number Note
It is possible for the unit’s initial hit points to differ from the maximum hit points.
See also
-
getInitialResources() → resources¶ Retrieves the amount of resources contained in the unit at the beginning of the game.
The unit must be a neutral resource container.
Returns: Amount of resources that this unit started with or 0if this unit was not a neutral unit at the beginning of the game, or if this unit does not contain resources. It is possible that the unit simply contains 0 resources.See also
-
getKillCount() → kills¶ Retrieves the number of units that this unit has killed in total.
Note
The maximum amount of recorded kills per unit is 255.
Returns: integer indicating this unit’s kill count. Return type: number
-
getAcidSporeCount() → count¶ Retrieves the number of acid spores that this unit is inflicted with.
Returns: Number of acid spores on this unit. Return type: number
-
getInterceptorCount() → count¶ Retrieves the number of interceptors that this unit manages.
This function is only for the
Carrierand its hero.Returns: Number of interceptors in this unit. Return type: number Note
This number may differ from the number of units returned from
getInterceptors(). This occurs for cases in which you can see the number of enemy interceptors in the Carrier HUD, but don’t actually have access to the individual interceptors.See also
-
getScarabCount() → count¶ Retrieves the number of scarabs that this unit has for use.
This function is only for the
Reaver.Returns: Number of scarabs this unit has ready. Return type: number
-
getSpiderMineCount() → count¶ Retrieves the amount of
Spider Minesthis unit has available.This function is only for the
Vulture <BWAPI.UnitTypes.Terran_Vulture.Returns: Number of spider mines available for placement. Return type: number
-
getGroundWeaponCooldown() → framesLeft¶ Retrieves the unit’s ground weapon cooldown.
This value decreases every frame, until it reaches 0. When the value is 0, this indicates that the unit is capable of using its ground weapon, otherwise it must wait until it reaches 0.
Note
This value will vary, because Starcraft adds an additional random value between (-1) and (+2) to the unit’s weapon cooldown.
Returns: Number of frames needed for the unit’s ground weapon to become available again. Return type: number
-
getAirWeaponCooldown() → framesLeft¶ Retrieves the unit’s air weapon cooldown.
This value decreases every frame, until it reaches 0. When the value is 0, this indicates that the unit is capable of using its air weapon, otherwise it must wait until it reaches 0.
Note
This value will vary, because Starcraft adds an additional random value between (-1) and (+2) to the unit’s weapon cooldown.
Returns: Number of frames needed for the unit’s air weapon to become available again. Return type: number
-
getSpellCooldown() → framesLeft¶ Retrieves the unit’s ability cooldown.
This value decreases every frame, until it reaches 0. When the value is 0, this indicates that the unit is capable of using one of its special abilities, otherwise it must wait until it reaches 0.
Note
This value will vary, because Starcraft adds an additional random value between (-1) and (+2) to the unit’s ability cooldown.
Returns: Number of frames needed for the unit’s abilities to become available again. Return type: number
-
getDefenseMatrixPoints() → hp¶ Retrieves the amount of hit points remaining on the
Defensive Matrixcreated by aScience Vessel.The
Defensive Matrixability starts with 250 hit points when it is used.Returns: Number of hit points remaining on this unit’s Defensive Matrix.Return type: number See also
-
getDefenseMatrixTimer() → framesLeft¶ Retrieves the time, in frames, that the
Defensive Matrixwill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getEnsnareTimer() → framesLeft¶ Retrieves the time, in frames, that
Ensnarewill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getIrradiateTimer() → framesLeft¶ Retrieves the time, in frames, that
Irradiatewill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getLockdownTimer() → framesLeft¶ Retrieves the time, in frames, that
Lockdownwill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
isLockdowned()
-
getMaelstromTimer() → framesLeft¶ Retrieves the time, in frames, that
Maelstromwill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getOrderTimer() → framesLeft¶ Retrieves an internal timer used for the primary order.
Its use is specific to the order type that is currently assigned to the unit.
Returns: A value used as a timer for the primary order. Return type: number See also
-
getPlagueTimer() → framesLeft¶ Retrieves the time, in frames, that
Plaguewill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getRemoveTimer() → framesLeft¶ Retrieves the time, in frames, until this temporary unit is destroyed or removed. Once this value reaches 0, the unit is destroyed.
This is used to determine the remaining time for the following units that were created by abilities:
Returns: Number of frames remaining until the unit is destroyed or removed. Return type: number
-
getStasisTimer() → framesLeft¶ Retrieves the time, in frames, that
Stasis Fieldwill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getStimTimer() → framesLeft¶ Retrieves the time, in frames, that
Stim Packswill remain active on the current unit.Returns: Number of frames remaining until the effect is removed. Return type: number See also
-
getBuildType() → type¶ Retrieves the building type that a worker (
SCV,Probe,Drone) is about to construct.If the unit is morphing or is an incomplete structure, then this returns the
UnitTypethat it will become when it has completed morphing/constructing.Returns: UnitTypeindicating the type that a worker (SCV,Probe,Drone) is about to construct, or the type that an incomplete unit will be when completed.Return type: UnitType
-
getTrainingQueue() → queue¶ Retrieves the list of units queued up to be trained.
Important
See the differences between the C++ and Lua implementations of this function for more information
Returns: An array-like table containing all of the UnitType‘s that are in this building’s training queue.Return type: table of the format {1 = UnitType, 2 =UnitType, ...}See also
-
getTech() → tech¶ Retrieves the technology that this unit is currently researching.
Returns: TechTypeindicating the technology being researched by this unit, orNoneif this unit is not researching anything.Return type: TechType
-
getUpgrade() → upgrade¶ Retrieves the upgrade that this unit is currently upgrading.
Returns: UpgradeTypeindicating the upgrade in progress by this unit, orNoneif this unit is not upgrading anything.Return type: UpgradeType
-
getRemainingBuildTime() → framesLeft¶ Retrieves the remaining build time for a unit or structure that is being trained or constructed.
Returns: Number of frames remaining until the unit’s completion. Return type: number
-
getRemainingResearchTime() → framesLeft¶ Retrieves the amount of time until the unit is done researching its currently assigned
TechType.Returns: The remaining research time, in frames, for the current technology being researched by this unit, or 0if the unit is not researching anything.Return type: number See also
-
getRemainingTrainTime() → framesLeft¶ Retrieves the remaining time, in frames, of the unit that is currently being trained.
Note
If the unit is a
Hatchery,Lair, orHive, this retrieves the amount of time until the next larva spawns.Returns: Number of frames remaining until the current training unit becomes completed, or the number of frames remaining until the next larva spawns, or 0if the unit is not training or has three larvae.Return type: number See also
-
getRemainingUpgradeTime() → framesLeft¶ Retrieves the amount of time until the unit is done upgrading its current upgrade.
Returns: The remaining upgrade time, in frames, for the current upgrade, or 0if the unit is not upgrading anything.Return type: number See also
-
getBuildUnit() → unit¶ Retrieves the unit currently being trained, or the corresponding paired unit for
SCVsandTerranstructures, depending on the context.For example, if this unit is a
Factoryunder construction, this function will return theSCVthat is constructing it. If this unit is aSCV, then it will return the structure it is currently constructing. If this unit is aNexus, and it is training aProbe, then the probe will be returned.Warning
This will return an incorrect unit when called on
Reavers.Returns: Paired build unit that is either constructing this unit or being constructed by this unit, structure being constructed by this unit, the unit that is being trained by this structure, or nilif there is no unit constructing this one or this unit is not constructing another unit.Return type: Unit
-
getTarget() → unit¶ Generally returns the appropriate target unit after issuing an order that accepts a target unit (i.e. attack, repair, gather, etc.).
To get a target that has been acquired automatically without issuing an order, use
getOrderTarget().Returns: Unit that is currently being targeted by this unit. Return type: UnitSee also
-
getTargetPosition() → position¶ Retrieves the target position the unit is moving to, provided a valid path to the target position exists.
Returns: Target position of a movement action. Return type: Position
-
getOrder() → order¶ Retrieves the primary
Orderthat the unit is assigned.Primary orders are distinct actions such as
AttackUnitandPlayerGuard.Returns: The primary Orderthat the unit is executing.Return type: Order
-
getSecondaryOrder() → order¶ Retrieves the secondary
Orderthat the unit is assigned.Secondary orders are run in the background as a sub-order. An example would be
TrainFighter, because aCarriercan move and train fighters at the same time.Returns: The secondary Orderthat the unit is executing.Return type: Order
-
getOrderTarget() → unit¶ Retrieves the unit’s primary order target.
This is usually set when the low level unit AI acquires a new target automatically. For example if an enemy
Probecomes in range of yourMarine, theMarinewill start attacking it, and getOrderTarget will be set in this case, but not getTarget.Returns: The Unit that this unit is currently targetting. Return type: UnitSee also
-
getOrderTargetPosition() → position¶ Retrieves the target position for the unit’s order.
For example, when
Moveis assigned,getTargetPosition()returns the end of the unit’s path, but this returns the location that the unit is trying to move to.Returns: Position that this unit is currently targetting. Return type: PositionSee also
-
getRallyPosition() → position¶ Retrieves the position the structure is rallying units to once they are completed.
Returns: Position that a completed unit coming from this structure will travel to, or Noneif this building does not produce units.Return type: PositionNote
If
getRallyUnit()is valid, then this value is ignored.See also
-
getRallyUnit() → unit¶ Retrieves the unit the structure is rallying units to once they are completed.
Units will then follow the targetted unit.
Returns: Unit that a completed unit coming from this structure will travel to, or nilif the structure is not rallied to a unit or it does not produce units.Return type: UnitNote
A rallied unit takes precedence over a rallied position. That is if the return value is valid (non-nil), then
getRallyPosition()is ignored.See also
-
getAddon() → unit¶ Retrieves the add-on that is attached to this unit.
Returns: Unit interface that represents the add-on that is attached to this unit, or nilif this unit does not have an add-on.Return type: Unit
-
getNydusExit() → unit¶ Retrieves the
Nydus Canalthat is attached to this one.Every
Nydus Canalcan place a “Nydus Exit” which, when connected, can be travelled through byZergunits.Returns: Unit interface representing the Nydus Canalconnected to this one, ornilif the unit is not aNydus Canal, is not owned, or has not placed a Nydus Exit.Return type: Unit
-
getPowerUp() → unit¶ Retrieves the power-up that the worker unit is holding.
Power-ups are special units such as the
Flagin theCapture The Flaggame type, which can be picked up by worker units.Returns: The Unit interface object that represents the power-up, or nilif the unit is not carrying anything.Return type: UnitExample¶local myUnits = BWAPI.Broodwar:self():getUnits() for u in myUnits:iterator() do -- If we are carrying a flag if u:getPowerUp() u:getPowerUp():getType() == BWAPI.UnitTypes.Powerup_Flag then local pred = function(x) return BWAPI.Filter.IsFlagBeacon(x) and BWAPI.Filter.IsOwned(x) end -- return it to our flag beacon to score u:move( u:getClosestUnit(pred) ) end end
Note
If your bot is strictly melee/1v1, then this method is not necessary.
Note
If this function returns a successful state, then the following function calls will also return a successful state:
getType():isWorker(),isCompleted()
-
getTransport() → unit¶ Retrieves the transport unit (
Dropship,Shuttle,Overlord) orBunkerunit that has this unit loaded inside of it.Returns: The unit that this unit is loaded inside of, or nilif the unit is not loaded inside of a unit.Return type: Unit
-
getLoadedUnits() → units¶ Retrieves the set of units that are contained within this
Bunker,Dropship,Shuttle, orOverlord.Returns: A Unitsetcontaining all of the units that are loaded inside of the current unit.Return type: Unitset
-
getSpaceRemaining() → spaceRemaining¶ Retrieves the remaining unit-space available for
Bunkersand transports (Dropships,Shuttles,Overlords).Returns: The number of spots available to transport a unit. Return type: number See also
-
getCarrier() → unit¶ Retrieves the parent
Carrierthat owns thisInterceptor.Returns: The parent Carrierunit that has ownership of this one, ornilif the current unit is not anInterceptor.Return type: Unit
-
getInterceptors() → units¶ Retrieves the set of
Interceptorscontrolled by this unit.This is intended for
Carriersand its hero.Returns: UnitsetcontainingInterceptorunits owned by this carrier.Return type: UnitsetSee also
-
getHatchery() → unit¶ Retrieves the parent
Hatchery,Lair, orHivethat owns this particular unit.This is intended for
Larvae.Returns: Hatchery unit that has ownership of this larva, or nilif the current unit is not aLarvaor has no parent.Return type: UnitSee also
-
getLarva() → units¶ Retrieves the set of
Larvaethat were spawned by this unit.Only
Hatcheries,Lairs, andHivesare capable of spawningLarvae. This is like clicking the “Select Larva” button and getting the selection ofLarvae.Returns: UnitsetcontainingLarvaunits owned by this unit. The set will be empty if there are none.Return type: UnitsetSee also
-
getUnitsInRadius(radius[, pred]) → units¶ Retrieves the set of all units in a given radius of the current unit.
Takes into account this unit’s dimensions. Can optionally specify a filter to include only specific units (such as only ground units, etc.)
Parameters: - radius (number) – The radius, in pixels, to search for units.
- pred (function) – (optional) A predicate function that takes a
Unitand returnstruefor units that satisfy the intended filter andfalseotherwise (can be a BWAPI.Filter unary filter). Defaults tonil, which means no filter.
Returns: A
Unitsetcontaining the set of units that match the given criteria.Return type: Example usage¶-- Get main building closest to start location. local isResourceDepotPred = function(x) return BWAPI.Filter.IsResourceDepot(x) end local main = BWAPI.Broodwar:getClosestUnit( BWAPI.Broodwar:self():getStartLocation(), isResourceDepotPred ) if main then -- check if main is valid -- Get sets of resources and workers local myResources = main:getUnitsInRadius(1024, BWAPI.Filter.IsMineralField); if not myResources:empty() then -- check if we have resources nearby local workerPred = function(x) BWAPI.Filter.IsWorker(x) and BWAPI.Filter.IsIdle(x) and BWAPI.Filter.IsOwned(x) end local myWorkers = main:getUnitsInRadius(512, workerPred) local myResourcesArray = myResources:asTable() for worker in myWorkers:iterator() do local randomResource = myResourcesArray[math.random(#myResourcesArray)] worker:gather(randomResource) end end end
-
getUnitsInWeaponRange(weapon[, pred]) → units¶ Obtains the set of units within weapon range of this unit.
Parameters: - weapon (BWAPI.WeaponType) – The weapon type to use as a filter for distance and units that can be hit by it.
- pred (function) – (optional) A predicate function that takes a
Unitand returnstruefor units that satisfy the intended filter andfalseotherwise (can be a BWAPI.Filter unary filter). If omitted, no additional filter is used.
Returns: The set of units within weapon range of this unit.
Return type:
-
getClosestUnit([pred][, radius = 999999]) → unit¶ Retrieves the closest unit to this one.
Parameters: - pred (function) – (optional) A predicate function that takes a
Unitand returnstruefor units that satisfy the intended filter andfalseotherwise (can be a BWAPI.Filter unary filter). Ifpredis omitted ornil, then the closest unit owned by any player will be returned. - radius (number) – (optional) The maximum radius to check for the closest unit. For performance reasons, a developer can limit the radius that is checked. If omitted, then the entire map is checked.
Returns: The closest unit that matches the predicate, or
nilif no matching unit is found.Return type: - pred (function) – (optional) A predicate function that takes a
-
hasNuke() → bool¶ Checks if the current unit is housing a
Nuke.This is only available for
Nuclear Silos.Returns: trueif this unit has aNukeready, andfalseif there is noNuke.Return type: boolean
-
isAccelerating() → bool¶ Checks if the current unit is accelerating.
Returns: trueif this unit is accelerating, andfalseotherwiseReturn type: boolean
-
isAttacking() → bool¶ Checks if this unit is currently attacking something.
Returns: trueif this unit is attacking another unit, andfalseif it is not.Return type: boolean
-
isAttackFrame() → bool¶ Checks if this unit is currently playing an attack animation.
Issuing commands while this returns
truemay interrupt the unit’s next attack sequence.Returns: trueif this unit is currently running an attack frame, andfalseif interrupting the unit is feasible.Return type: boolean Note
This function is only available to some unit types, specifically those that play special animations when they attack.
-
isBeingConstructed() → bool¶ Checks if the current unit is being constructed.
This is mostly applicable to Terran structures which require an SCV to be constructing a structure.
Returns: trueif this is either a Protoss structure, Zerg structure, or Terran structure being constructed by an attached SCV, andfalseif this is either completed, not a structure, or has no SCV constructing it.Return type: boolean
-
isBeingGathered() → bool¶ Checks this
Mineral FieldorRefineryis currently being gathered from.Returns: trueif this unit is a resource container and being harvested by a worker, andfalseotherwiseReturn type: boolean
-
isBeingHealed() → bool¶ Checks if this unit is currently being healed by a
Medicor repaired by aSCV.Returns: trueif this unit is being healed, andfalseotherwise.Return type: boolean
-
isBlind() → bool¶ Checks if this unit is currently blinded by a
Medic‘sOptical Flareability.Blinded units have reduced sight range and cannot detect other units.
Returns: trueif this unit is blind, andfalseotherwiseReturn type: boolean
-
isBraking() → bool¶ Checks if the current unit is slowing down to come to a stop.
Returns: trueif this unit is breaking,falseif it has stopped or is still moving at full speed.Return type: boolean
-
isBurrowed() → bool¶ Checks if the current unit is burrowed, either using the
Burrowability, or is an armedSpider Mine.Returns: trueif this unit is burrowed, andfalseotherwiseReturn type: boolean See also
-
isCarryingGas() → bool¶ Checks if this worker unit is carrying some vespene gas.
Returns: trueif this is a worker unit carrying vespene gas, andfalseif it is either not a worker, or not carrying gas.Return type: boolean Example¶local myUnits = BWAPI.Broodwar:self():getUnits() for u in myUnits:iterator() do if u:isIdle() and (u:isCarryingGas() or u:isCarryingMinerals()) then u:returnCargo() end end
Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted(),getType():isWorker()See also
-
isCarryingMinerals() → bool¶ Checks if this worker unit is carrying some minerals.
Returns: trueif this is a worker unit carrying minerals, andfalseif it is either not a worker, or not carrying minerals.Return type: boolean Example¶local myUnits = BWAPI.Broodwar:self():getUnits() for u in myUnits:iterator() do if u:isIdle() and (u:isCarryingGas() or u:isCarryingMinerals()) then u:returnCargo() end end
Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted(),getType():isWorker()See also
-
isCloaked() → bool¶ Checks if this unit is currently
cloaked.Returns: trueif this unit is cloaked, andfalseif it is visible.Return type: boolean
-
isCompleted() → bool¶ Checks if this unit has finished being constructed, trained, morphed, or warped in, and can now receive orders.
Returns: trueif this unit is completed, andfalseif it is under construction or inaccessible.Return type: boolean
-
isConstructing() → bool¶ Checks if a unit is either constructing something or moving to construct something.
Returns: truewhen a unit has been issued an order to build a structure and is moving to the build location, or is currently constructing something.Return type: boolean
-
isDefenseMatrixed() → bool¶ Checks if this unit has the
Defensive Matrixeffect.Returns: trueif theDefensive Matrixability was used on this unit, andfalseotherwise.Return type: boolean
-
isDetected() → bool¶ Checks if this unit is visible or revealed by a detector unit.
If this is
falseand isVisible istrue, then the unit is only partially visible and requires a detector in order to be targetted.Returns: trueif this unit is detected, andfalseif it needs a detector unit nearby in order to see it.Return type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isVisible()
-
isEnsnared() → bool¶ Checks if the
QueenabilityEnsnarehas been used on this unit.Returns: trueif the unit is ensnared, andfalseif it is notReturn type: boolean
-
isFlying() → bool¶ This macro function checks if this unit is in the air.
That is, the unit is either a flyer or a flying building.
Returns: trueif this unit is in the air, andfalseif it is on the groundReturn type: boolean See also
-
isFollowing() → bool¶ Checks if this unit is following another unit.
When a unit is following another unit, it simply moves where the other unit does, and does not attack enemies when it is following.
Returns: trueif this unit is following another unit, andfalseif it is notReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted()See also
-
isGatheringGas() → bool¶ Checks if this unit is currently gathering gas.
That is, the unit is either moving to a refinery, waiting to enter a refinery, harvesting from the refinery, or returning gas to a resource depot.
Returns: trueif this unit is harvesting gas, andfalseif it is notReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted(),getType():isWorker()See also
-
isGatheringMinerals() → bool¶ Checks if this unit is currently harvesting minerals.
That is, the unit is either moving to a
Mineral Field, waiting to mine, mining minerals, or returning minerals to a resource depot.Returns: trueif this unit is gathering minerals, andfalseif it is notReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted(),getType():isWorker()See also
-
isHallucination() → bool¶ Checks if this unit is a hallucination.
Hallucinations are created by the
High Templarusing theHallucinationability. Enemy hallucinations are unknown ifBWAPI.Flag.CompleteMapInformationis disabled. Hallucinations have a time limit until they are destroyed (seegetRemoveTimer()).Returns: trueif the unit is a hallucination andfalseotherwise.Return type: boolean See also
-
isHoldingPosition() → bool¶ Checks if the unit is currently holding position.
A unit that is holding position will attack other units, but will not chase after them.
Returns: trueif this unit is holding position, andfalseif it is not.Return type: boolean See also
-
isIdle() → bool¶ Checks if this unit is running an idle order.
This function is particularly useful when checking for units that aren’t doing any tasks that you assigned.
A unit is considered idle if it is not doing any of the following:
- Training
- Constructing
- Morphing
- Researching
- Upgrading
In addition to running one of the following orders:
PlayerGuard: Player unit idle.Guard: Generic unit idle.StopPickupIdleNothing: Structure/generic idle.Medic: Medic idle.Carrier: Carrier idle.Reaver: Reaver idle.Critter: Critter idle.Neutral: Neutral unit idle.TowerGuard: Turret structure idle.Burrowed: Burrowed unit idle.NukeTrainLarva: Larva idle.
Example¶local myUnits = BWAPI.Broodwar:self():getUnits() for u in myUnits:iterator() do -- Order idle worker to gather from closest mineral field if u:getType():isWorker() and u:isIdle() then u:gather( u:getClosestUnit( BWAPI.Filter.IsMineralField ) ) end end
Returns: trueif this unit is idle, andfalseif this unit is performing any action, such as moving or attackingReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted()See also
-
isInterruptible() → bool¶ Checks if the unit can be interrupted.
Returns: trueif this unit can be interrupted, orfalseif this unit is uninterruptableReturn type: boolean
-
isInvincible() → bool¶ Checks the invincibility state for this unit.
Returns: trueif this unit is currently invulnerable, andfalseif it is vulnerableReturn type: boolean
-
isInWeaponRange(target) → bool¶ Checks if the target unit can immediately be attacked by this unit in the current frame.
Parameters: target (BWAPI.Unit) – The target unit to use in this check. Returns: trueiftargetis within weapon range of this unit’s appropriate weapon, andfalseiftargetis invalid, inaccessible, too close, too far, or this unit does not have a weapon that can attacktarget.Return type: boolean
-
isIrradiated() → bool¶ Checks if this unit is irradiated by a
Science Vessel‘sIrradiateability.Example¶local myUnits = BWAPI.Broodwar:self():getUnits() for u in myUnits:iterator() do if u:isIrradiated() and u:getIrradiateTimer > 50 and BWAPI.Broodwar:self():hasResearched(BWAPI.TechTypes.Restoration) then local medicPred = function(x) return BWAPI.Filter.GetType(x) == BWAPI.UnitTypes.Terran_Medic and BWAPI.Filter.Energy(x) >= BWAPI.TechTypes.Restoration:energyCost() end local medic = u:getClosestUnit( medicPred ) if medic then medic:useTech(BWAPI.TechTypes.Restoration, u) end end end
Returns: trueif this unit is irradiated, andfalseotherwiseReturn type: boolean See also
-
isLifted() → bool¶ Checks if this unit is a
Terranbuilding and lifted off the ground.This function generally implies
getType():isBuilding()andisCompleted()both return true.Returns: trueif this unit is aTerranstructure lifted off the ground.Return type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted(),getType():isFlyingBuilding()See also
-
isLoaded() → bool¶ Checks if this unit is currently loaded into another unit such as a Transport (
Dropship,Shuttle,Overlord).Returns: trueif this unit is loaded in another one, andfalseotherwiseReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
isCompleted()See also
-
isLockedDown() → bool¶ Checks if this unit is currently
lockedby aGhost.Returns: trueif this unit is locked down, andfalseotherwiseReturn type: boolean See also
-
isMaelstrommed() → bool¶ Checks if this unit has been
maelstrommedby aDark Archon.Returns: trueif this unit is maelstrommed, andfalseotherwiseReturn type: boolean See also
-
isMorphing() → bool¶ Finds out if the current unit is morphing or not.
Zergunits and structures often have the ability to morph into different types of units. This function allows you to identify when this process is occurring.Returns: trueif the unit is currently morphing, andfalseif the unit is not morphing.Return type: boolean See also
morph(),cancelMorph(),getBuildType(),getRemainingBuildTime()
-
isMoving() → bool¶ Checks if this unit is currently moving.
Returns: trueif this unit is moving, andfalseif it is notReturn type: boolean See also
-
isParasited() → bool¶ Checks if this unit has been parasited by some other player.
Returns: trueif this unit is inflicted withParasite, andfalseif it is cleanReturn type: boolean
-
isPatrolling() → bool¶ Checks if this unit is patrolling between two positions.
Returns: trueif this unit is patrolling andfalseif it is notReturn type: boolean See also
-
isPlagued() → bool¶ Checks if this unit has been been
plaguedby aDefiler.Returns: trueif this unit is inflicted withPlagueand is taking damage, andfalseif it is cleanReturn type: boolean See also
-
isRepairing() → bool¶ Checks if this unit is repairing or moving to
repairanother unit.This is only applicable to
SCVs.Returns: trueif this unit is currently repairing or moving torepairanother unit, andfalseif it is notReturn type: boolean
-
isResearching() → bool¶ Checks if this unit is a structure that is currently researching a technology.
See
TechTypesfor a complete list of technologies in Broodwar.Returns: trueif this structure is researching a technology,falseotherwiseReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
exists(),isCompleted(),getType():isBuilding()
-
isSelected() → bool¶ Checks if this unit has been selected in the user interface.
This function is only available if the flag
BWAPI.Flag.UserInputis enabled.Returns: trueif this unit is currently selected, andfalseif this unit is not selectedReturn type: boolean See also
-
isSieged() → bool¶ Checks if this unit is currently
sieged.This is only applicable to
Siege Tanks.Returns: trueif the unit is in siege mode, andfalseif it is either not in siege mode or not aSiege TankReturn type: boolean
-
isStartingAttack() → bool¶ Checks if the unit is starting to attack.
Returns: trueif this unit is starting an attack.Return type: boolean
-
isStasised() → bool¶ Checks if this unit is inflicted with
Stasis Fieldby anArbiter.Returns: trueif this unit is locked in aStasis Fieldand is unable to move, andfalseif it is free.Return type: boolean Note
This function does not necessarily imply that the unit is invincible, since there is a feature in the
Use Map Settingsgame type that allows stasised units to be vulnerable.See also
-
isStimmed() → bool¶ Checks if this unit is currently under the influence of a
Stim Packs.Returns: trueif this unit has used a stim pack,falseotherwiseReturn type: boolean See also
-
isStuck() → bool¶ Checks if this unit is currently trying to resolve a collision by randomly moving around.
Returns: trueif this unit is currently stuck and trying to resolve a collision, andfalseif this unit is freeReturn type: boolean
-
isTraining() → bool¶ Checks if this unit is training a new unit.
For example, a
Barrackstraining aMarine.Note
It is possible for a unit to remain in the training queue with no progress. In that case, this function will return
falsebecause of supply or unit count limitations.Returns: trueif this unit is currently training another unit, andfalseotherwise.
-
isUnderAttack() → bool¶ Checks if the current unit is being attacked.
Has a small delay before this returns
falseagain when the unit is no longer being attacked.Returns: trueif this unit has been attacked within the past few frames, andfalseif it has notReturn type: boolean
-
isUnderDarkSwarm() → bool¶ Checks if this unit is under the cover of a
Dark Swarm.Returns: trueif this unit is protected by aDark Swarm, andfalseif it is notReturn type: boolean
-
isUnderDisruptionWeb() → bool¶ Checks if this unit is currently being affected by a
Disruption Web.Returns: trueif this unit is under the effects ofDisruption Web.Return type: boolean
-
isUnderStorm() → bool¶ Checks if this unit is currently taking damage from a
Psionic Storm.Returns: trueif this unit is losing hit points from aPsionic Storm, andfalseotherwise.Return type: boolean
-
isPowered() → bool¶ Checks if this unit has power.
Most structures are powered by default, but
Protossstructures require aPylonto be powered and functional.Returns: trueif this unit has power or is inaccessible, andfalseif this unit is unpowered.Return type: boolean
-
isUpgrading() → bool¶ Checks if this unit is a structure that is currently upgrading an upgrade.
See
BWAPI.UpgradeTypesfor a full list of upgrades in Broodwar.Returns: trueif this structure is upgrading,falseotherwiseReturn type: boolean Note
If this function returns a successful state, then the following function calls will also return a successful state:
exists(),isCompleted(),getType():isBuilding()
-
isVisible([player]) → bool¶ Checks if this unit is visible.
Parameters: player (BWAPI.Player) – (optional) The player to check visibility for. If this parameter is omitted, then the BWAPI player obtained from Game.self()will be used.Returns: trueif this unit is visible to the specifiedplayer, andfalseif it is not.Return type: boolean Note
If the
BWAPI.Flag.CompleteMapInformationflag is enabled, existing units hidden by the fog of war will be accessible, butisVisible()will still return false.See also
-
isTargetable() → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to be targetted as the target unit of an unspecified command.
Returns: trueif BWAPI was unable to determine whether the unit can be a target, andfalseif an error occurred and the unit can not be a target.Return type: boolean See also
-
issueCommand(command) → wasIssued¶ This function issues a command to the unit, however it is used for interfacing only, and is recommended to use one of the more specific command functions when writing an AI.
Parameters: command (BWAPI.UnitCommand) – The command to be issued Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
attack(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit(s) to attack move to the specified position or attack the specified unit.
Parameters: - target (
BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit. If a Position is used, the unit will perform an Attack Move command. - shiftQueueCommand (bool) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
A
Medicwill use Heal Move instead of attack.See also
- target (
-
build(type[, target]) → wasIssued¶ Orders the worker unit(s) to construct a structure at a target position.
Parameters: - type (BWAPI.UnitType) – The
UnitTypeto build. - target (BWAPI.TilePosition) – A TilePosition to specify the build location, specifically the upper-left corner of the location. If the target is not specified, then the function call will be redirected to the train command.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
Note
You must have sufficient resources and meet the necessary requirements in order to build a structure.
See also
Game.getLastError(),train(),cancelConstruction(),canBuild()- type (BWAPI.UnitType) – The
-
buildAddon(type) → wasIssued¶ Orders the
Terranstructure(s) to construct an add-on.Parameters: type (BWAPI.UnitType) – The add-on UnitTypeto construct.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
Note
You must have sufficient resources and meet the necessary requirements in order to build a structure.
See also
Game.getLastError(),build(),cancelAddon(),canBuildAddon()
-
train([type]) → wasIssued¶ Orders the unit(s) to add a
UnitTypeto its training queue, or morphs into theUnitTypeif it isZerg.Parameters: type (BWAPI.UnitType) – The UnitTypeto train. If the type is not specified, then this function will have no effect unless this unit is a Carrier or Reaver, in which case the type will default toInterceptorsorScarabs.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
Note
You must have sufficient resources, supply, and meet the necessary requirements in order to train a unit.
Note
This command is also used for training
InterceptorsandScarabs.Note
If you call this using a
Hatchery,Lair, orHive, then it will automatically pass the command to one of itsLarvae.See also
Game.getLastError(),build(),morph(),cancelTrain(),isTraining(),canTrain()
-
morph(type) → wasIssued¶ Orders the unit(s) to morph into a different
UnitType.Parameters: type (BWAPI.UnitType) – The UnitTypeto morph into.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
research(tech) → wasIssued¶ Orders the unit to research the given tech type.
Parameters: tech (BWAPI.TechType) – The TechTypeto research.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
upgrade(upgrade) → wasIssued¶ Orders the unit to upgrade the given upgrade type.
Parameters: upgrade (BWAPI.UpgradeType) – The UpgradeTypeto upgrade.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
setRallyPoint(target) → wasIssued¶ Orders the unit to set its rally position to the specified position or unit.
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit. The target position or target unit that this structure will rally to.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
move(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to move from its current position to the specified position.
Parameters: - target (BWAPI.Position) – The target position to move to.
- shiftQueueCommand (boolean) – (optional) If this value is
true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
patrol(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to patrol between its current position and the specified position.
While patrolling, units will attack and chase enemy units that they encounter, and then return to its patrol route.
Medicswill automatically heal units and then return to their patrol route.Parameters: - target (BWAPI.Position) – The target position to patrol to.
- shiftQueueCommand (boolean) – (optional) If this value is
true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
holdPosition([shiftQueueCommand = false]) → wasIssued¶ Orders the unit to hold its position.
Parameters: shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default. Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
stop([shiftQueueCommand = false]) → wasIssued¶ Orders the unit to stop.
Parameters: shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default. Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
follow(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to follow the specified unit.
Units that are following other units will not perform any other actions such as attacking. They will ignore attackers.
Parameters: - target (BWAPI.Unit) – The target unit to start following.
- shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
gather(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to gather the specified unit (must be mineral or refinery type).
Parameters: - target (BWAPI.Unit) – The target unit to gather from.
- shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
returnCargo([shiftQueueCommand = false]) → wasIssued¶ Orders the unit to return its cargo to a nearby resource depot such as a Command Center.
Only workers that are carrying minerals or gas can be ordered to return cargo.
Parameters: shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default. Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
repair(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to repair the specified unit.
Only Terran SCVs can be ordered to repair, and the target must be a mechanical
Terranunit or building.Parameters: - target (BWAPI.Unit) – The target unit to repair.
- shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
burrow() → wasIssued¶ Orders the unit to burrow.
Either the unit must be a
Lurker, or the unit must be aZergground unit that is capable ofBurrowing, andBurrowtechnology must be researched.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
unburrow() → wasIssued¶ Orders a burrowed unit to unburrow.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cloak() → wasIssued¶ Orders the unit to cloak.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
decloak() → wasIssued¶ Orders a cloaked unit to decloak.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
siege() → wasIssued¶ Orders the unit to siege.
Only works for
Siege Tanks.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
unsiege() → wasIssued¶ Orders the unit to unsiege.
Only works for sieged
Siege Tanks.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
lift() → wasIssued¶ Orders the unit to lift.
Only works for liftable
Terranstructures.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
land(target) → wasIssued¶ Orders the unit to land.
Only works for
Terranstructures that are currently lifted.Parameters: target`` (BWAPI.TilePosition) – The tile position to land this structure at. Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
load(target[, shiftQueueCommand = false]) → wasIssued¶ Orders the unit to load the target unit.
Only works if this unit is a Transport (
Dropship,Shuttle,Overlord) orBunkertype.Parameters: - target (BWAPI.Unit) – The target unit to load into this Transport (
Dropship,Shuttle,Overlord) orBunker. - shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
- target (BWAPI.Unit) – The target unit to load into this Transport (
-
unload(target) → wasIssued¶ Orders the unit to unload the target unit.
Only works for Transports (
Dropships,Shuttles,Overlords) andBunkers.Parameters: target (BWAPI.Unit) – Unloads the target unit from this Transport( Dropship,Shuttle,Overlord) orBunker.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
load(),unloadAll(),getLoadedUnits(),isLoaded(),canUnload(),canUnloadAtPosition()
-
unloadAll([shiftQueueCommand = false]) → wasIssued¶ Orders the unit to unload all loaded units at the unit’s current position.
Only works for Transports (
Dropships,Shuttles,Overlords) andBunkers.Parameters: shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default. Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
load(),unload(),getLoadedUnits(),isLoaded(),canUnloadAll(),canUnloadAtPosition()
-
unloadAll(target[, shiftQueueCommand = false]) → wasIssued Orders the unit to unload all loaded units at the specified location.
Only works for Transports (
Dropships,Shuttles,Overlords)Important
Not applicable to
Bunkers.Parameters: - target (BWAPI.Position) – The target position to unload the units at.
- shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
rightClick(target[, shiftQueueCommand = false]) → wasIssued¶ Works like the right click in the GUI.
Parameters: - target (
BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit. The target position or target unit to right click. - shiftQueueCommand (boolean) – (optional) If this value is true, then the order will be queued instead of immediately executed. If this value is omitted, then the order will be executed immediately by default.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
Note
There is a small chance for a command to fail after it has been passed to Broodwar.
- target (
-
haltConstruction() → wasIssued¶ Orders a
SCVto stop constructing a structure.This leaves the structure in an incomplete state until it is either cancelled, razed, or completed by another
SCV.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cancelConstruction() → wasIssued¶ Orders this unit to cancel and refund itself from begin constructed.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cancelAddon() → wasIssued¶ Orders this unit to cancel and refund an add-on that is being constructed.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cancelTrain([slot = -2]) → wasIssued¶ Orders the unit to remove the specified unit from its training queue.
Important
The first
slothas an index of1. See the differences between the C++ and Lua implementations of this function for more information.Parameters: slot (number) – (optional) Identifies the slot that will be cancelled. If the specified value is at least 1, then the unit in the corresponding slot from the list provided by getTrainingQueue()will be cancelled. If the slot is either omitted or-2, then the last slot is cancelled.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
Zero and negative values other than
-2have no effect.Note
There is a small chance for a command to fail after it has been passed to Broodwar.
-
cancelMorph() → wasIssued¶ Orders this unit to cancel and refund a unit that is morphing.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cancelResearch() → wasIssued¶ Orders this unit to cancel and refund a research that is in progress.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
cancelUpgrade() → wasIssued¶ Orders this unit to cancel and refund an upgrade that is in progress.
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
See also
-
useTech([tech][, target]) → wasIssued¶ Orders the unit to use a technology.
Parameters: - tech (BWAPI.TechType) – The technology type to use.
- target (
BWAPI.PositionorBWAPI.Unit) – (optional) Can be either aPositionorUnit. If specified, indicates the target location or unit to use the tech on. If unspecified, causes thetechto be used without a target (i.e.Stim Packs).
Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean
-
placeCOP(target) → bool¶ Moves a
Flag Beaconto a different location.This is only used for
Capture The FlagorUse Map Settingsgame types.Parameters: target (BWAPI.TilePosition) – The target tile position to place the Flag Beacon.Returns: trueif the command was passed to Broodwar, andfalseif BWAPI determined that the command would fail.Return type: boolean Note
There is a small chance for a command to fail after it has been passed to Broodwar.
Note
This command is only available for the first 10 minutes of the game, as in Broodwar.
See also
canPlaceCOP
-
canIssueCommand(command[, checkCanUseTechPositionOnPositions = true, checkCanUseTechUnitOnUnits = true, checkCanBuildUnitType = true, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute the given command.
If you are calling this function repeatedly (e.g. to generate a collection of valid commands), you can avoid repeating the same kinds of checks by specifying
falsefor some of the optional boolean arguments. Make sure that the state hasn’t changed since the check was done though (eg a new frame/event, or a command issued). Also see the more specific functions.Parameters: - command (BWAPI.UnitCommand) – A
UnitCommandto check. - checkCanUseTechPositionOnPositions (boolean) – Only used if the command type is
BWAPI.UnitCommandTypes.Use_Tech_Position. A boolean for whether to perform cheap checks for whether the unit is unable to target any positions using the command’sTechType(i.e. regardless of what the other command parameters are). You can set this tofalseif you know this check has already just been performed. - checkCanUseTechUnitOnUnits (boolean) – Only used if the command type is
BWAPI.UnitCommandTypes.Use_Tech_Unit. A boolean for whether to perform cheap checks for whether the unit is unable to target any units using the command’sTechType(i.e. regardless of what the other command parameters are). You can set this tofalseif you know this check has already just been performed. - checkCanBuildUnitType (boolean) – Only used if the command type is
BWAPI.UnitCommandTypes.Build. A boolean for whether to perform cheap checks for whether the unit is unable to build the specifiedUnitType(i.e. regardless of what the other command parameters are). You can set this tofalseif you know this check has already just been performed. - checkCanTargetUnit (boolean) – Only used for command types that can target a unit. A boolean for whether to perform
canTargetUnit()as a check. You can set this tofalseif you know this check has already just been performed. - checkCanIssueCommandType (boolean) – A boolean for whether to perform
Unit.canIssueCommandType()as a check. You can set this tofalseif you know this check has already just been performed. - checkCommandibility (boolean) – A boolean for whether to perform
canCommand()as a check. You can set this tofalseif you know this check has already just been performed.
Returns: trueif BWAPI determined that the command is valid, orfalseif an error occurred and the command is invalidReturn type: boolean
- command (BWAPI.UnitCommand) – A
-
canIssueCommandGrouped(command[, checkCanUseTechPositionOnPositions = true, checkCanUseTechUnitOnUnits = true, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute the given command as part of a
Unitset(even if none of the units in theUnitsetare able to execute the command individually).The reason this function exists is because some commands are valid for an individual unit but not for those individuals as a group (e.g. buildings, critters) and some commands are only valid for a unit if it is commanded as part of a unit group, e.g.:
- attackMove/attackUnit for a
Unitset, some of which can’t attack, e.g.High Templar. This is supported simply for consistency with BW’s behaviour - you could issue move command(s) individually instead. - attackMove/move/patrol/rightClickPosition for air unit(s) + e.g.
Larva, as part of the air stacking technique. This is supported simply for consistency with BW’s behaviour - you could issue move/patrol/rightClickPosition command(s) for them individually instead.
Note
BWAPI allows the following special cases to command a unit individually (rather than only allowing it to be commanded as part of a
Unitset). These commands are not available to a user in BW when commanding units individually, but BWAPI allows them for convenience:- attackMove/attackUnit for a
-
canCommand() → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to execute any commands (eg the unit is stasised).
Returns: trueif BWAPI was unable to determine whether the unit can be commanded, orfalseif an error occurred and the unit can not be commanded.Return type: boolean See also
-
canCommandGrouped([checkCommandibility = true]) → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to execute any commands as part of a
Unitset(eg buildings, critters).Returns: trueif BWAPI was unable to determine whether the unit can be commanded grouped, orfalseif an error occurred and the unit can not be commanded grouped.Return type: boolean
-
canIssueCommandType(commandType[, checkCommandibility = true]) → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to execute the given command type (i.e. regardless of what other possible command parameters could be).
Parameters: - commandType (BWAPI.UnitCommandType) – A
UnitCommandType. - checkCommandibility (boolean) – A boolean for whether to perform
canCommand()as a check. You can set this tofalseif you know this check has already just been performed.
Returns: trueif BWAPI was unable to determine whether the command type is invalid, orfalseif an error occurred and the command type is invalid.Return type: boolean
- commandType (BWAPI.UnitCommandType) – A
-
canIssueCommandTypeGrouped(commandType[, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to execute the given command type (i.e.
regardless of what other possible command parameters could be) as part of a
Unitset.Parameters: - commandType (BWAPI.UnitCommandType) – A
UnitCommandType. - checkCommandibilityGrouped (boolean) – A boolean for whether to perform
canCommandGrouped()as a check. You can set this tofalseif you know this check has already just been performed. - checkCommandibility (boolean) – A boolean for whether to perform
canCommand()as a check. You can set this tofalseif you know this check has already just been performed.
Returns: trueif BWAPI was unable to determine whether the command type is invalid, orfalseif an error occurred and the command type is invalid.- commandType (BWAPI.UnitCommandType) – A
-
canTargetUnit(targetUnit[, checkCommandibility = true]) → bool¶ Performs some cheap checks to attempt to quickly detect whether the unit is unable to use the given unit as the target unit of an unspecified command.
Parameters: - targetUnit (BWAPI.Unit) – A target unit for an unspecified command.
- checkCommandibility (boolean) – A boolean for whether to perform
canCommand()as a check. You can set this tofalseif you know this check has already just been performed.
Returns: trueif BWAPI was unable to determine whether the unit can target the given unit, orfalseif an error occurred and the unit can not target the given unit.
-
canAttack([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an attack command to attack-move or attack a unit.
-
canAttack(target[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an attack command to attack-move or attack a (non-null) unit.
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canAttackGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an attack command to attack-move or attack a unit, as part of a
Unitset.
-
canAttackGrouped(target[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an attack command to attack-move or attack a (non-null) unit, as part of a
Unitset.Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canAttackMove([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute an attack command to attack-move.
See also
-
canAttackMoveGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute an attack command to attack-move, as part of a
Unitset.
-
canAttackUnit([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an attack command to attack a unit.
See also
-
canAttackUnit(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an attack command to attack a unit.
Parameters: targetUnit (BWAPI.Unit) – See also
-
canAttackUnitGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an attack command to attack a unit, as part of a
Unitset.
-
canAttackUnitGrouped(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an attack command to attack a unit, as part of a
Unitset.Parameters: targetUnit (BWAPI.Unit) –
-
canBuild([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a build command.
See also
-
canBuild(unitType[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Cheap checks for whether the unit is able to execute a build command for the given
UnitType.Parameters: unitType (BWAPI.UnitType) – See also
-
canBuild(unitType, tilePos[, checkTargetUnitType = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a build command.
Parameters: - unitType (BWAPI.UnitType) –
- tilePos (BWAPI.TilePosition) –
See also
-
canBuildAddon([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a buildAddon command.
-
canBuildAddon(unitType[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a buildAddon command.
Parameters: unitType (BWAPI.UnitType) –
-
canTrain([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a train command.
See also
-
canTrain(unitType[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a train command.
Parameters: unitType (BWAPI.UnitType) – See also
-
canMorph([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a morph command.
See also
-
canMorph(unitType[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a morph command.
Parameters: unitType (BWAPI.UnitType) – See also
-
canResearch([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a research command.
See also
-
canResearch(type[, checkCanIssueCommandType = true]) → bool Checks whether the unit is able to execute a research command.
Parameters: type (BWAPI.TechType) – See also
-
canUpgrade([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an upgrade command.
See also
-
canUpgrade(type[, checkCanIssueCommandType = true]) → bool Checks whether the unit is able to execute an upgrade command.
Parameters: type (BWAPI.UpgradeType) – See also
-
canSetRallyPoint([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a setRallyPoint command to a position or unit.
-
canSetRallyPoint(target[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a setRallyPoint command to a position or (non-null) unit.
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canSetRallyPosition([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a setRallyPoint command to a position.
-
canSetRallyUnit([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a setRallyPoint command to a unit.
-
canSetRallyUnit(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a setRallyPoint command to a unit.
Parameters: targetUnit (BWAPI.Unit) –
-
canMove([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a move command.
See also
-
canMoveGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a move command, as part of a
Unitset.
-
canPatrol([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a patrol command.
See also
-
canPatrolGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a patrol command, as part of a
Unitset.
-
canFollow([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a follow command.
See also
-
canFollow(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a follow command.
Parameters: targetUnit (BWAPI.Unit) – See also
-
canGather([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a gather command.
See also
-
canGather(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a gather command.
Parameters: targetUnit (BWAPI.Unit) – See also
-
canReturnCargo([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a returnCargo command.
-
canHoldPosition([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a holdPosition command.
-
canStop([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a stop command.
See also
-
canRepair([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a repair command.
See also
-
canRepair(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a repair command.
Parameters: targetUnit (BWAPI.Unit) – See also
-
canBurrow([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a burrow command.
See also
-
canUnburrow([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute an unburrow command.
See also
-
canCloak([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cloak command.
See also
-
canDecloak([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a decloak command.
See also
-
canSiege([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a siege command.
See also
-
canUnsiege([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute an unsiege command.
See also
-
canLift([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a lift command.
See also
-
canLand([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a land command.
See also
-
canLand(target[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a land command.
Parameters: target (BWAPI.TilePosition) – See also
-
canLoad(checkCommandibility = true) → bool¶ Cheap checks for whether the unit is able to execute a load command.
See also
-
canLoad(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a load command.
Parameters: targetUnit (BWAPI.Unit) – See also
-
canUnloadWithOrWithoutTarget([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an unload command or unloadAll at current position command or unloadAll at a different position command.
See also
Game.getLastError(),Unit.canIssueCommand(),unload(),unloadAll()
-
canUnloadAtPosition(target[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an unload command or unloadAll at current position command or unloadAll at a different position command, for a given position.
Parameters: target (BWAPI.Position) – See also
Game.getLastError(),Unit.canIssueCommand(),unload(),unloadAll()
-
canUnload([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an unload command.
See also
-
canUnload(targetUnit[, checkCanTargetUnit = true, checkPosition = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an unload command.
Parameters: targetUnit (BWAPI.Unit) –
-
canUnloadAll([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute an unloadAll command for the current position.
See also
-
canUnloadAllPosition([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute an unloadAll command for a different position.
See also
-
canUnloadAllPosition(target[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute an unloadAll command for a different position.
Parameters: target (BWAPI.Position) – See also
-
canRightClick([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a rightClick command to a position or unit.
-
canRightClick(target[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a rightClick command to a position or (non-null) unit.
Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canRightClickGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a rightClick command to a position or unit, as part of a
Unitset.
-
canRightClickGrouped(target[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a rightClick command to a position or (non-null) unit, as part of a
Unitset.Parameters: target ( BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canRightClickPosition([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a rightClick command for a position.
-
canRightClickPositionGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a rightClick command for a position, as part of a
Unitset.
-
canRightClickUnit([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a rightClick command to a unit.
-
canRightClickUnit(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a rightClick command to a unit.
Parameters: targetUnit (BWAPI.Unit) –
-
canRightClickUnitGrouped([checkCommandibilityGrouped = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a rightClick command to a unit, as part of a
Unitset.
-
canRightClickUnitGrouped(targetUnit[, checkCanTargetUnit = true, checkCanIssueCommandType = true, checkCommandibilityGrouped = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a rightClick command to a unit, as part of a
Unitset.Parameters: targetUnit (BWAPI.Unit) –
-
canHaltConstruction([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a haltConstruction command.
-
canCancelConstruction([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelConstruction command.
-
canCancelAddon([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelAddon command.
-
canCancelTrain([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelTrain command for any slot.
-
canCancelTrainSlot([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a cancelTrain command for an unspecified slot.
-
canCancelTrainSlot(slot[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a cancelTrain command for a specified slot.
Parameters: slot (number) – Important
The first
slothas an index of1. SeecancelTrain()and the differences between the C++ and Lua implementations of this function for more information.
-
canCancelMorph([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelMorph command.
-
canCancelResearch([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelResearch command.
-
canCancelUpgrade([checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a cancelUpgrade command.
-
canUseTechWithOrWithoutTarget([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a useTech command without a target or or a useTech command with a target position or a useTech command with a target unit.
See also
-
canUseTechWithOrWithoutTarget(tech[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Cheap checks for whether the unit is able to execute a useTech command without a target or or a useTech command with a target position or a useTech command with a target unit, for a given
TechType.Parameters: tech (BWAPI.TechType) – See also
-
canUseTech(tech[, target, checkCanTargetUnit = true, checkTargetsType = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a useTech command for a specified position or unit (only specify nullptr if the
TechTypedoes not target another position/unit).Parameters: - tech (BWAPI.TechType) –
- target (
BWAPI.PositionorBWAPI.Unit) – Can be either aPositionorUnit.
-
canUseTechWithoutTarget(tech[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a useTech command without a target.
Parameters: tech (BWAPI.TechType) – See also
-
canUseTechUnit(tech[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a useTech command with an unspecified target unit.
Parameters: tech (BWAPI.TechType) – See also
-
canUseTechUnit(tech, targetUnit[, checkCanTargetUnit = true, checkTargetsUnits = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a useTech command with a target unit.
Parameters: - tech (BWAPI.TechType) –
- targetUnit (BWAPI.Unit) –
See also
-
canUseTechPosition(tech[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool¶ Checks whether the unit is able to execute a useTech command with an unspecified target position.
Parameters: tech (BWAPI.TechType) – See also
-
canUseTechPosition(tech, target[, checkTargetsPositions = true, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a useTech command with a target position.
Parameters: - tech (BWAPI.TechType) –
- target (BWAPI.Position) –
See also
-
canPlaceCOP([checkCommandibility = true]) → bool¶ Cheap checks for whether the unit is able to execute a placeCOP command.
See also
-
canPlaceCOP(target[, checkCanIssueCommandType = true, checkCommandibility = true]) → bool Checks whether the unit is able to execute a placeCOP command.
Parameters: target (BWAPI.TilePosition) – See also
-
registerEvent(action[, condition = nil][, timesToRun = -1][, framesToCheck = 0])¶ Registers an event and associates it with the current object.
Events can be used to automate tasks (like train X Marines until Y of them have been created by the given Barracks) or to create user-defined callbacks.
Parameters: - action (function) – The callback to be executed when the event conditions are true.
- condition (function) – (optional) The condition callback which will return true if the action is intended to be executed. The condition will always be true if omitted.
- timesToRun (int) – (optional) The number of times to execute the action before the event is removed. If the value is negative, then the event will never be removed. The value will be -1 if omitted, causing the event to execute until the game ends.
- framesToCheck (int) – (optional) The number of frames to skip between checks. If this value is 0, then a condition check is made once per frame. If this value is 1, then the condition for this event is only checked every other frame. This value is 0 by default, meaning the event’s condition is checked every frame.
-