Difference between revisions of "Oolite JavaScript Reference: Entity"

From Elite Wiki
(Removed Oolite 1.75 change notes.)
(owner: This should be mentioned)
(9 intermediate revisions by 3 users not shown)
Line 14: Line 14:
 
=== <code>distanceTravelled</code> ===
 
=== <code>distanceTravelled</code> ===
 
  '''distanceTravelled''' : Number (read-only)
 
  '''distanceTravelled''' : Number (read-only)
The distance the entity has travelled since being spawned, in game meters.
+
The distance the entity has travelled since being spawned, in game meters. It only tracks the distance change generated by thrust. (useful for missiles). Distance traveled by an initial velocity, like with cargo pods, is not added in this value.
  
 
=== <code>energy</code> ===
 
=== <code>energy</code> ===
Line 26: Line 26:
 
<code>entity.heading()</code> is equivalent to <code>entity.[[#orientation|orientation]].[[Oolite JavaScript Reference: Quaternion#forwardVector|forwardVector]]()</code>.
 
<code>entity.heading()</code> is equivalent to <code>entity.[[#orientation|orientation]].[[Oolite JavaScript Reference: Quaternion#forwardVector|forwardVector]]()</code>.
  
=== <code>mass</code> ===
+
=== <code>isDock</code> ===
  '''mass''' : Number (read-only)
+
{{oolite-prop-added|1.77}}
The mass of the entity. Currently, this is directly proportional to the volume.
+
  '''isDock''' : Boolean (read-only)
 
+
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Dock|Dock]], <code>false</code> otherwise.
=== <code>maxEnergy</code> ===
 
'''maxEnergy''' : Number (read-only)
 
The highest permissible value of <code>[[#energy|energy]]</code>.
 
  
=== <code>orientation</code> ===
+
=== <code>isInSpace</code> ===
'''orientation''' : [[Oolite JavaScript Reference: Quaternion|Quaternion]] (read/write)
+
{{oolite-prop-added|1.77}}
 
+
  '''isInSpace''' : Boolean (read-only)
=== <code>owner</code> ===
+
<code>true</code> if the entity is currently independently in real space, <code>false</code> otherwise (e.g. dead, docked, in a hold, in witchspace, etc.)
  '''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.
 
 
 
=== <code>position</code> ===
 
'''position''' : [[Oolite JavaScript Reference: Vector|Vector]] (read/write)
 
 
 
=== <code>scanClass</code> ===
 
'''scanClass''' : String (read-only)
 
The current scan class of the entity (such as “CLASS_NEUTRAL” and “CLASS_CARGO”).
 
 
 
=== <code>spawnTime</code> ===
 
'''spawnTime''' : Number (read-only)
 
The time at which the entity came into existence.
 
 
 
=== <code>status</code> ===
 
'''status''' : String (read-only)
 
The current status of the entity (such as “STATUS_IN_FLIGHT” and “STATUS_BEING_SCOOPED”).
 
  
 
=== <code>isPlanet</code> ===
 
=== <code>isPlanet</code> ===
Line 83: Line 63:
 
  '''isValid''' : Boolean (read-only)
 
  '''isValid''' : Boolean (read-only)
 
<code>true</code> if the entity is a valid entity variable, <code>false</code> if it is [[#Stale References|stale]].
 
<code>true</code> if the entity is a valid entity variable, <code>false</code> if it is [[#Stale References|stale]].
 +
 +
=== <code>isVisible</code> ===
 +
{{Oolite-prop-added|1.77}}
 +
'''isVisible''' : Boolean (read-only)
 +
Determines if the entity is close enough to the player to be drawn.
 +
 +
=== <code>isVisualEffect</code> ===
 +
{{oolite-prop-added|1.77}}
 +
'''isVisualEffect''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: VisualEffect|VisualEffect]], <code>false</code> otherwise.
 +
 +
=== <code>isWormhole</code> ===
 +
{{Oolite-prop-added|1.79}}
 +
'''isWormhole''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Wormhole|Wormhole]], <code>false</code> otherwise.
 +
 +
=== <code>mass</code> ===
 +
'''mass''' : Number (read-only)
 +
The mass of the entity. Currently, this is directly proportional to the volume.
 +
 +
=== <code>maxEnergy</code> ===
 +
'''maxEnergy''' : Number (read-only, read/write from 1.81)
 +
The highest permissible value of <code>[[#energy|energy]]</code>.
 +
 +
=== <code>orientation</code> ===
 +
'''orientation''' : [[Oolite JavaScript Reference: Quaternion|Quaternion]] (read/write)
 +
 +
=== <code>owner</code> ===
 +
'''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 an escort, the group leader. In the case of a missile, the ship that launched it. There may be other uses.
 +
 +
=== <code>position</code> ===
 +
'''position''' : [[Oolite JavaScript Reference: Vector|Vector]] (read/write)
 +
 +
=== <code>scanClass</code> ===
 +
'''scanClass''' : String (read-only)
 +
The current scan class of the entity (such as “CLASS_NEUTRAL” and “CLASS_CARGO”).
 +
 +
In 1.77 or later, this is partially read/write for Ship entities other than the PlayerShip.
 +
 +
=== <code>spawnTime</code> ===
 +
'''spawnTime''' : Number (read-only)
 +
The time at which the entity came into existence.
 +
 +
=== <code>status</code> ===
 +
'''status''' : String (read-only)
 +
The current status of the entity (such as “STATUS_IN_FLIGHT” and “STATUS_BEING_SCOOPED”).
  
 
[[Category:Oolite JavaScript Reference]]
 
[[Category:Oolite JavaScript Reference]]

Revision as of 16:12, 12 December 2015

Prototype: Object
Subtypes: Planet, Ship, Sun

The Entity class represents an object in the game universe. Ships, Stations, Planets and Suns are 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 isValid property.

Properties

collisionRadius

collisionRadius : Number (read-only)

The radius of the entity, in game meters. This is the radius of the spherical entity representation Oolite calculates with for non-colliding entities.

distanceTravelled

distanceTravelled : Number (read-only)

The distance the entity has travelled since being spawned, in game meters. It only tracks the distance change generated by thrust. (useful for missiles). Distance traveled by an initial velocity, like with cargo pods, is not added in this value.

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().

isDock

This property was added in Oolite test release 1.77.

isDock : Boolean (read-only)

true if the entity is a Dock, false otherwise.

isInSpace

This property was added in Oolite test release 1.77.

isInSpace : Boolean (read-only)

true if the entity is currently independently in real space, false otherwise (e.g. dead, docked, in a hold, in witchspace, etc.)

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 ship, 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.

isVisible

This property was added in Oolite test release 1.77.

isVisible : Boolean (read-only)

Determines if the entity is close enough to the player to be drawn.

isVisualEffect

This property was added in Oolite test release 1.77.

isVisualEffect : Boolean (read-only)

true if the entity is a VisualEffect, false otherwise.

isWormhole

This property was added in Oolite test release 1.79.

isWormhole : Boolean (read-only)

true if the entity is a Wormhole, false otherwise.

mass

mass : Number (read-only)

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

maxEnergy

maxEnergy : Number (read-only, read/write from 1.81)

The highest permissible value of energy.

orientation

orientation : Quaternion (read/write)

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 an escort, the group leader. In the case of a missile, the ship that launched it. There may be other uses.

position

position : Vector (read/write)

scanClass

scanClass : String (read-only)

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

In 1.77 or later, this is partially read/write for Ship entities other than the PlayerShip.

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”).