Difference between revisions of "Oolite JavaScript Reference: ShipGroup"

From Elite Wiki
m (Moving Oolite JS reference into a *correctly-named* subcategory of Oolite scripting.)
(Stylistic homogenization.)
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 ==
 
== Constructor ==
 
  '''new ShipGroup'''() : ShipGroup
 
  '''new ShipGroup'''() : ShipGroup
Creates a new group to which ships can be added. e.g.
+
Creates a new group
 +
 
 +
'''Example:'''
 
  var myGroup = new ShipGroup();
 
  var myGroup = new ShipGroup();
 
  myGroup.name = "My group";
 
  myGroup.name = "My group";
Line 11: Line 11:
  
 
== Properties ==
 
== Properties ==
=== <code>ships</code> ===
+
=== <code>count</code> ===
  '''ships''' : Array of entites (read-only)
+
  '''count''' : Integer (read-only)
 +
Number of ships in the group, including leader.
  
 
=== <code>leader</code> ===
 
=== <code>leader</code> ===
 
  '''leader''' : Entity (read/write)
 
  '''leader''' : Entity (read/write)
Defines a leader for the group. When the ship is not on the group list, he is added to the group.  
+
Defines a leader for the group. If the ship is not a member of the group, it is added.
  
 
=== <code>name</code> ===
 
=== <code>name</code> ===
 
  '''name''' : String (read/write)
 
  '''name''' : String (read/write)
Name of the shipgroup.
+
Name of the ship group.
  
=== <code>count</code> ===
+
=== <code>ships</code> ===
  '''count''' : Integer (read-only)
+
  '''ships''' : Array of entites (read-only)
Number of ships in the group, including leader.
 
  
  
 
== Methods ==
 
== Methods ==
=== <code>toString</code> ===
+
=== <code>addShip</code> ===
  function '''toString'''()
+
  function '''addShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]])
Returns the whole group as a human readable string.
+
Add a ship to the group.
  
=== <code>addShip</code> ===
+
=== <code>containsShip</code> ===
  function '''addShip'''([ship : Entity])
+
  function '''containsShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]]) : Boolean
Adds an entity to a group.
+
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'''([ship : Entity])
+
  function '''removeShip'''(ship : [[Oolite JavaScript Reference: Ship|Ship]])
Removes an entity to a group.
+
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 JavaScript Reference]]
 
[[Category:Oolite JavaScript Reference]]

Revision as of 15:35, 20 June 2010

The ShipGroup class is used to manage groups of ships.

Constructor

new ShipGroup() : ShipGroup

Creates a new group

Example:

var myGroup = new ShipGroup();
myGroup.name = "My group";
myShip.group = myGroup;

Properties

count

count : Integer (read-only)

Number of ships in the group, including leader.

leader

leader : Entity (read/write)

Defines a leader for the group. If the ship is not a member of the group, it is added.

name

name : String (read/write)

Name of the ship group.

ships

ships : Array of entites (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.