Difference between revisions of "Oolite JavaScript Reference: Entity"

From Elite Wiki
(Removed ancient deprecated method)
(<code>ID</code>)
Line 28: Line 28:
  
 
=== <code>ID</code> ===
 
=== <code>ID</code> ===
 +
{{Oolite-script-item-deprecated|property|1.74}}
 
  '''ID''' : Number (read-only, integer)
 
  '''ID''' : Number (read-only, integer)
 
The [[#Universal IDs|universal ID]] of the entity.
 
The [[#Universal IDs|universal ID]] of the entity.

Revision as of 23:08, 5 September 2009

Prototype: Object
Subtypes: Planet, Ship, Sun

This class was added in Oolite test release 1.70.

The Entity class represents an object in the game universe. Ships, Stations, Planets and the Playerare types of entity. Note that these more specific types have additional properties and methods.

Stale References

When an entity dies or is otherwise removed from the game universe (for instance, because player jumped from the system), existing Entity variables referring to the entity become invalid; all their properties become undefined, and their methods do nothing. In addition to the undefined properties, this can be detected with the valid() method.

Universal IDs

Every Entity has an unique universal ID. All Oolite-provided functions which take an Entity as an argument may also be passed an integer representing the Entity’s ID.

Properties

distanceTravelled

distanceTravelled : Number (read-only)

The distance the entity has travelled since being spawned, in game metres.

energy

energy : Number (read/write)

The entity’s total energy; ranges from 0 to maxEnergy.

heading

heading : Vector (read-only)

The heading of the entity. This is equivalent to orientation, but ignoring the axial twist component (roll in the case of a ship).

entity.heading() is equivalent to entity.orientation.forwardVector().

ID

This property is deprecated and will be removed in Oolite test release 1.74.

ID : Number (read-only, integer)

The universal ID of the entity.

mass

mass : Number (read-only)

The mass of the entity. Currently, this is directly proportional to the volume.

maxEnergy

maxEnergy : Number (read-only)

The highest permissible value of energy.

orientation

orientation : Quaternion (read-only)

The spacial orientation of the entity.

See Also: setOrientation()

owner

owner : Entity (read-only)

The entity which owns this one. In the case of a subentity, the entity to which it is attached. In the case of a defense ship, the station it belongs to. In the case of a missile, the ship that launched it. There may be other uses.

position

position : Vector (read-only)

The position of the entity in system co-ordinates.

See Also: setPosition()

scanClass

scanClass : String (read-only)

The current scan class of the entity (such as “CLASS_NEUTRAL” and “CLASS_CARGO”).

spawnTime

spawnTime : Number (read-only)

The time at which the entity came into existence.

status

status : String (read-only)

The current status of the entity (such as “STATUS_IN_FLIGHT” and “STATUS_BEING_SCOOPED”).

isPlanet

isPlanet : Boolean (read-only)

true if the entity is a Planet, false otherwise.

isPlayer

isPlayer : Boolean (read-only)

true if the entity is the Player, false otherwise.

isShip

isShip : Boolean (read-only)

true if the entity is a Ship, false otherwise.

isStation

isStation : Boolean (read-only)

true if the entity is a Station, false otherwise.

isSubEntity

isSubEntity : Boolean (read-only)

true if the entity is a subentity, false otherwise. A subentity’s owner can be acquired through the owner property.

isSun

isSun : Boolean (read-only)

true if the entity is a Sun, false otherwise.

isValid

isValid : Boolean (read-only)

true if the entity is a valid entity variable, false if it is stale.

Methods

call

function call(methodName : String, ...)

Call a method on the underlying Objective-C class. This is the same approach taken by script actions in plist scripts and AI actions in AI plists. The first argument is the name of the method to call. If the method takes a parameter (in which case it will end with a colon), any number of additional arguments may be specified; these will be concatenated together, separated by spaces, and passed the requested method. If the underlying method returns a value, it will be returned from call(), otherwise the result will be undefined.

setOrientation

This property is deprecated and will be removed in Oolite test release 1.74.

function setOrientation(orientation : quaternionExpression)

Instantaneously rotate the entity to the specified orientation.

setPosition

This property is deprecated and will be removed in Oolite test release 1.74.

function setPosition(postion : vectorExpression)

Instantaneously move the entity to the specified position.

Static methods

Static methods are methods which can be called on Entity, rather than an entity variable. Example: var myEntity = Entity.entityWithID(142);

entityWithID

entityWithID(ID : Number (integer)) : Entity

Returns the entity with the specified universal ID.