Units

A units object is a collection of battle_unit objects. Like the other battle collection objects (battle_alliances and battle_armies), units:count returns the number of objects and units:item returns individual items in the collection.

Loaded in Campaign Loaded in Campaign
Loaded in Battle Loaded in Battle
Loaded in Frontend Loaded in Frontend
Back to top

Creation

Units objects are derived from battle_army objects in the battle_hierarchy - see the battle_hierarchy page for more information. Preferably, use the script_unit or generated_battle frameworks provided by the script libraries to negate the need to explicitly create units objects.

Back to top

Usage

Once a handle to a units object is obtained, functions may be called on it to query or modify its state in the following form.

Example - Specification:

<object_name>:<function_name>(<args>)

Example - Creation and Usage:

local units_player = bm:alliances():item(1):armies():item(1):units()
out("number of player units: " .. units_player:count())        -- calling a function on the object once created
number of player units: 7
Back to top

Methods

units:item(number index)

Returns the battle_unit at the specified index in the units list. The list is 1-based, so supplying 1 as an argument will return the first unit in the army.

Parameters:

1

number

index

Returns:

  1. battle_unit unit

defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 5111

units:count()

Returns the size of the units list.

Returns:

  1. number size of list

defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 5132

units:mountable_artillery_item(number index)

Returns the battle_unit at the specified index in the mountable artillery list. The list is also 1-based.

Parameters:

1

number

index

Returns:

  1. battle_unit unit

defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 5149

units:kill_commander()

Kills the commander of the army.

Returns:

  1. nil

defined in ../../common/EmpireBattle/Source/BattleScript/BattleEditorScriptInterface.cpp, line 5170

Last updated 12/08/2022 11:56:59