Difference between revisions of "Oolite JavaScript Reference: ShipGroup"
From Elite Wiki
Eric Walch (talk | contribs) (Added shipGroups entry) |
(→leader) |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{Oolite-class-added|1.73}} |
||
+ | The '''<code>ShipGroup</code>''' class is used to manage groups of ships. |
||
− | The '''<code>ShipGroup</code>''' class is a property of an <code>[[Oolite JavaScript Reference: Entity|Entity]]</code> representing a group of ships. |
||
+ | == Constructor == |
||
+ | '''new ShipGroup'''([name : String [, leader : {{oojsclass|Ship}}]]) : ShipGroup |
||
+ | Creates a new group, optionally specifying the <code>[[#name|name]]</code> and <code>[[#leader|leader]]</code>. |
||
+ | |||
+ | '''Example:''' |
||
+ | var myGroup = new ShipGroup(); |
||
+ | myGroup.name = "My group"; |
||
+ | myShip.group = myGroup; |
||
== Properties == |
== Properties == |
||
− | === <code> |
+ | === <code>count</code> === |
− | ''' |
+ | '''count''' : Number (integer, read-only) |
+ | Number of ships in the group, including leader. |
||
=== <code>leader</code> === |
=== <code>leader</code> === |
||
− | '''leader''' : |
+ | '''leader''' : Ship (read/write) |
+ | Defines a leader for the group. If the ship is not a member of the group, it is added. |
||
+ | '''Note:''' The player's ship can be set as a group leader, but doing this is not recommended. The lack of JS AIs for the player means that exceptions during script execution and other unpredictable behaviour can be expected and, are in fact, very likely. This is a known issue in versions of the game up to and including 1.84. |
||
=== <code>name</code> === |
=== <code>name</code> === |
||
'''name''' : String (read/write) |
'''name''' : String (read/write) |
||
− | Name of the |
+ | Name of the ship group. |
− | === <code> |
+ | === <code>ships</code> === |
− | ''' |
+ | '''ships''' : Array ([[Oolite JavaScript Reference: Ship|Ship]]s, read-only) |
− | Number of ships in the group, including leader. |
||
== Methods == |
== Methods == |
||
− | === <code>toString</code> === |
||
− | function '''toString'''() |
||
− | Returns the whole group as a human readable string. |
||
− | |||
=== <code>addShip</code> === |
=== <code>addShip</code> === |
||
− | function '''addShip'''( |
+ | function '''addShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]]) |
− | + | Add a ship to the group. |
|
+ | |||
+ | === <code>containsShip</code> === |
||
+ | function '''containsShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]]) : Boolean |
||
+ | Returns <code>true</code> if <code>ship</code> is a member of the group, <code>false</code> otherwise. |
||
=== <code>removeShip</code> === |
=== <code>removeShip</code> === |
||
− | function '''removeShip'''( |
+ | function '''removeShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]]) |
− | + | Remove a ship from the group. |
|
− | === <code>containsShip</code> === |
||
− | function '''containsShip'''([ship : Entity]) |
||
− | Boolean, returns true when the ship belongs to the group. When not it returns false. |
||
− | [[Category:Oolite |
+ | [[Category:Oolite JavaScript Reference]] |
Latest revision as of 18:24, 18 July 2016
The ShipGroup
class is used to manage groups of ships.
Contents
Constructor
new ShipGroup([name : String [, leader : Ship
]]) : ShipGroup
Creates a new group, optionally specifying the name
and leader
.
Example:
var myGroup = new ShipGroup(); myGroup.name = "My group"; myShip.group = myGroup;
Properties
count
count : Number (integer, read-only)
Number of ships in the group, including leader.
leader
leader : Ship (read/write)
Defines a leader for the group. If the ship is not a member of the group, it is added. Note: The player's ship can be set as a group leader, but doing this is not recommended. The lack of JS AIs for the player means that exceptions during script execution and other unpredictable behaviour can be expected and, are in fact, very likely. This is a known issue in versions of the game up to and including 1.84.
name
name : String (read/write)
Name of the ship group.
ships
ships : Array (Ships, read-only)
Methods
addShip
function addShip(ship : Ship)
Add a ship to the group.
containsShip
function containsShip(ship : Ship) : Boolean
Returns true
if ship
is a member of the group, false
otherwise.
removeShip
function removeShip(ship : Ship)
Remove a ship from the group.