Factorio.com|Forums|Wiki|Mod Portal|API Docs

# Factorio Runtime Docs Version 2.0.77

# LuaCommandable - Runtime Docs

## Class LuaCommandable

AI object which can be ordered commands. This can represent a UnitGroup (a set of multiple commandables) or can be a single Unit or SpiderUnit.

## Members

destroy() |  | Destroys this commandable. [...]
Destroys this commandable. [...]
set_command(command) |  | Give this commandable a command.
Give this commandable a command.
set_distraction_command(command) |  | Give this commandable a distraction command.
Give this commandable a distraction command.
release_from_spawner() |  | Release the commandable from the spawner. [...]
Release the commandable from the spawner. [...]
add_member(member) |  | Adds a member to this UnitGroup. [...]
Adds a member to this UnitGroup. [...]
set_autonomous() |  | Make this group autonomous. [...]
Make this group autonomous. [...]
start_moving() |  | Make the group start moving even if some of its members haven't yet arrived.
Make the group start moving even if some of its members haven't yet arrived.
is_unit_group | :: R boolean | If this commandable is UnitGroup.
If this commandable is UnitGroup.
is_entity | :: R boolean | If this commandable is Entity.
If this commandable is Entity.
surface | :: R LuaSurface | Surface this commandable is on.
Surface this commandable is on.
position | :: R MapPosition | Current position of this commandable. [...]
Current position of this commandable. [...]
force | :: R LuaForce | The force of this commandable.
The force of this commandable.
unique_id | :: R uint32 | Unique identifier of this commandable.
Unique identifier of this commandable.
has_command | :: R boolean | If this commandable has a command assigned.
If this commandable has a command assigned.
command | :: R Command? | The command of this commandable, if any.
The command of this commandable, if any.
distraction_command | :: R Command? | The distraction command of this commandable, if any.
The distraction command of this commandable, if any.
parent_group | :: R LuaCommandable? | The unit group this commandable is a member of, if any.
The unit group this commandable is a member of, if any.
spawner | :: R LuaEntity? | The spawner associated with this commandable, if any.
The spawner associated with this commandable, if any.
moving_state | :: R defines.moving_state | Current moving state of the commandable's behavior
Current moving state of the commandable's behavior
state | :: R defines.group_state | Whether this group is gathering, moving or attacking.
Whether this group is gathering, moving or attacking.
members | :: R array[LuaEntity] | All entity members of this unit group, recursive (if unit group is member of this unit group, its members will be returned here).
All entity members of this unit group, recursive (if unit group is member of this unit group, its members will be returned here).
commandable_members | :: R array[LuaCommandable] | Non recursively returns all members of this unit group.
Non recursively returns all members of this unit group.
is_script_driven | :: R boolean | Whether this unit group is controlled by a script or by the game engine. [...]
Whether this unit group is controlled by a script or by the game engine. [...]
entity | :: R LuaEntity | Returns entity object for this commandable.
Returns entity object for this commandable.
valid | :: R boolean | Is this object valid? [...]
Is this object valid? [...]
object_name | :: R string | The class name of this object. [...]
The class name of this object. [...]

## Methods

### destroy()

Destroys this commandable. If it is a unit group, members will not be destroyed, they will be merely unlinked from the group.

### set_command(command)

Give this commandable a command.

#### Parameters

command | :: Command |

### set_distraction_command(command)

Give this commandable a distraction command.

#### Parameters

command | :: Command |

### release_from_spawner()

Release the commandable from the spawner. This allows the spawner to continue spawning additional units.

### add_member(member)

Adds a member to this UnitGroup. Has the same effect as setting defines.command.group command on the member to join the group.

The member must have the same force be on the same surface as the group.

#### Parameters

member | :: LuaCommandable or LuaEntity |

Can only be used if this is UnitGroup

### set_autonomous()

Make this group autonomous. Autonomous groups will automatically attack polluted areas. Autonomous groups aren't considered to be script-driven.

Can only be used if this is UnitGroup

### start_moving()

Make the group start moving even if some of its members haven't yet arrived.

Can only be used if this is UnitGroup

## Attributes

### is_unit_group :: Read boolean

If this commandable is UnitGroup.

### is_entity :: Read boolean

If this commandable is Entity.

### surface :: Read LuaSurface

Surface this commandable is on.

### position :: Read MapPosition

Current position of this commandable.

If commandable is a UnitGroup, this can have different meanings depending on the group state. When the group is gathering, the position is the place of gathering. When the group is moving, the position is the expected position of its members along the path. When the group is attacking, it is the average position of its members.

### force :: Read LuaForce

The force of this commandable.

### unique_id :: Read uint32

Unique identifier of this commandable.

### has_command :: Read boolean

If this commandable has a command assigned.

### command :: Read Command?

The command of this commandable, if any.

### distraction_command :: Read Command?

The distraction command of this commandable, if any.

### parent_group :: Read LuaCommandable?

The unit group this commandable is a member of, if any.

### spawner :: Read LuaEntity?

The spawner associated with this commandable, if any.

### moving_state :: Read defines.moving_state

Current moving state of the commandable's behavior

### state :: Read defines.group_state

Whether this group is gathering, moving or attacking.

Can only be used if this is UnitGroup

### members :: Read array[LuaEntity]

All entity members of this unit group, recursive (if unit group is member of this unit group, its members will be returned here).

Can only be used if this is UnitGroup

### commandable_members :: Read array[LuaCommandable]

Non recursively returns all members of this unit group.

Can only be used if this is UnitGroup

### is_script_driven :: Read boolean

Whether this unit group is controlled by a script or by the game engine. This can be changed using LuaCommandable::set_autonomous. Units created by LuaSurface::create_unit_group are considered script-driven.

Can only be used if this is UnitGroup

### entity :: Read LuaEntity

Returns entity object for this commandable.

Can only be used if this is Entity

### valid :: Read boolean

Is this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be `false`. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.

### object_name :: Read string

The class name of this object. Available even when `valid` is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.

Class used in

- LuaCommandable::add_member()
- LuaCommandable::parent_group
- LuaCommandable::commandable_members
- LuaEntity::commandable
- LuaSurface::create_unit_group()
- Command
- CutsceneWaypoint
- RegistrationTarget
- on_build_base_arrived
- on_unit_added_to_group
- on_unit_group_created
- on_unit_group_finished_gathering
- on_unit_removed_from_group