Difference between revisions of "Oolite JavaScript Reference: Entity"

From Elite Wiki
m (Made position and orientation read-only (see [http://www.aegidian.org/bb/viewtopic.php?p=34504#34504]))
m (status: added string)
 
(56 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Oolite-future-scripting}}
+
<small>'''Prototype:''' <code>Object</code></small><br />
 +
<small>'''Subtypes:''' <code>[[Oolite JavaScript Reference: Planet|Planet]]</code>, <code>[[Oolite JavaScript Reference: Ship|Ship]]</code>, <code>[[Oolite JavaScript Reference: Sun|Sun]]</code></small>
  
The '''<code>Entity</code>''' class represents an object in the game universe – <code>[[Oolite/Development/Scripting/Class/Vessel|Vessel]]</code>s, <code>[[Oolite/Development/Scripting/Class/Station|Station]]</code>s and <code>[[Oolite/Development/Scripting/Class/CelestialBody|CelestialBody]]</code>s are common types of entity. Note that these more specific types have additional properties and methods.
+
The '''<code>Entity</code>''' class represents an object in the game universe. <code>[[Oolite JavaScript Reference: Ship|Ship]]</code>s, <code>[[Oolite JavaScript Reference: Station|Station]]</code>s, <code>[[Oolite JavaScript Reference: Planet|Planet]]</code>s and <code>[[Oolite JavaScript Reference: Sun|Sun]]</code>s are types of entity. Note that these more specific types have additional properties and methods.
  
=== Universal IDs ===
+
=== Stale References ===
Every <code>Entity</code> has an unique universal ID. All Oolite-provided functions which take an <code>Entity</code> as an argument may also be passed an integer representing the <code>Entity</code>’s ID.
+
When an entity dies or is otherwise removed from the game universe (for instance, because player jumped from the system), existing <code>Entity</code> variables referring to the entity become invalid; all their properties become <code>undefined</code>, and their methods do nothing. In addition to the undefined properties, this can be detected with the <code>[[#isValid|isValid]]</code> property.
  
 
== Properties ==
 
== Properties ==
=== <code>ID</code> ===
+
=== <code>collisionRadius</code> ===
  ID [read-only integer]
+
  '''collisionRadius''' : Number (read-only)
The [[#Universal IDs|universal ID]] of the entity.
+
The radius of the entity, in game meters. This is the radius of the spherical entity representation Oolite calculates with for non-colliding entities.
  
=== <code>position</code> ===
+
=== <code>distanceTravelled</code> ===
  position [read-only [[Oolite/Development/Scripting/Class/Vector|Vector]]]
+
  '''distanceTravelled''' : Number (read-only)
The position of the entity in system co-ordinates.
+
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> ===
 +
'''energy''' : Number (read/write)
 +
The entity’s total energy; ranges from 0 to <code>[[#maxEnergy|maxEnergy]]</code>.
 +
 
 +
=== <code>heading</code> ===
 +
'''heading''' : [[Oolite JavaScript Reference: Vector|Vector]] (read-only)
 +
The heading of the entity. This is equivalent to <code>[[#orientation|orientation]]</code>, but ignoring the axial twist component (roll in the case of a ship).
 +
 
 +
<code>entity.heading()</code> is equivalent to <code>entity.[[#orientation|orientation]].[[Oolite JavaScript Reference: Quaternion#forwardVector|forwardVector]]()</code>.
 +
 
 +
=== <code>isDock</code> ===
 +
{{oolite-prop-added|1.77}}
 +
'''isDock''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Dock|Dock]], <code>false</code> otherwise.
 +
 
 +
=== <code>isInSpace</code> ===
 +
{{oolite-prop-added|1.77}}
 +
'''isInSpace''' : Boolean (read-only)
 +
<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.)
 +
 
 +
=== <code>isPlanet</code> ===
 +
'''isPlanet''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Planet|Planet]], <code>false</code> otherwise.
 +
 
 +
=== <code>isPlayer</code> ===
 +
'''isPlayer''' : Boolean (read-only)
 +
<code>true</code> if the entity is the [[Oolite JavaScript Reference: PlayerShip|player ship]], <code>false</code> otherwise.
  
'''See Also:''' <code>[[#setPosition|setPosition]]()</code>
+
=== <code>isShip</code> ===
 +
'''isShip''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Ship|Ship]], <code>false</code> otherwise.
  
=== <code>velocity</code> ===
+
=== <code>isStation</code> ===
  velocity [read-only [[Oolite/Development/Scripting/Class/Vector|Vector]]]
+
  '''isStation''' : Boolean (read-only)
The velocity of the entity in system units (nominal metres) per second.
+
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Station|Station]], <code>false</code> otherwise.
  
=== <code>speed</code> ===
+
=== <code>isSubEntity</code> ===
  speed [read-only double]
+
  '''isSubEntity''' : Boolean (read-only)
The speed of the entity in system units (nominal metres) per second.
+
<code>true</code> if the entity is a subentity, <code>false</code> otherwise. A subentity’s owner can be acquired through the <code>[[#owner|owner]]</code> property.
  
<code>entity.speed()</code> is equivalent to <code>entity.[[#velocity|velocity]]().[[Oolite/Development/Scripting/Class/Vector#magnitude|magnitude]]()</code>.
+
=== <code>isSun</code> ===
 +
'''isSun''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Sun|Sun]], <code>false</code> otherwise.
  
=== <code>orientation</code> ===
+
=== <code>isSunlit</code> ===
  orientation [read-only [[Oolite/Development/Scripting/Class/Quaternion|Quaternion]]]
+
{{oolite-prop-added|1.89}}
The spacial orientation of the entity.
+
  '''isSunlit''' : Boolean (read-only)
 +
<code>true</code> if the entity is a currently being lit by the sun or <code>false</code> if in the shadow of another entity, like a planet or station.
  
'''See Also:''' <code>[[#setOrientation|setOrientation]]()</code>
+
=== <code>isValid</code> ===
 +
'''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>heading</code> ===
+
=== <code>isVisible</code> ===
  heading [read-only [[Oolite/Development/Scripting/Class/Vector|Vector]]]
+
{{Oolite-prop-added|1.77}}
The heading of the entity. This is equivalent to <code>[[#orientation|orientation]]</code>, but ignoring the axial twist component (roll in the case of a ship).
+
  '''isVisible''' : Boolean (read-only)
 +
Determines if the entity is close enough to the player to be drawn.
  
=== <code>status</code> ===
+
=== <code>isVisualEffect</code> ===
  status [read-only string]
+
{{oolite-prop-added|1.77}}
The current status of the entity (such as “STATUS_IN_FLIGHT” and “STATUS_BEING_SCOOPED”).
+
  '''isVisualEffect''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: VisualEffect|VisualEffect]], <code>false</code> otherwise.
  
=== <code>scanClass</code> ===
+
=== <code>isWormhole</code> ===
  scanClass [read-only string]
+
{{Oolite-prop-added|1.79}}
The current scan class of the entity (such as “CLASS_NEUTRAL” and “CLASS_CARGO”).
+
  '''isWormhole''' : Boolean (read-only)
 +
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Wormhole|Wormhole]], <code>false</code> otherwise.
  
 
=== <code>mass</code> ===
 
=== <code>mass</code> ===
  mass [read-only double]
+
  '''mass''' : Number (read-only)
 
The mass of the entity. Currently, this is directly proportional to the volume.
 
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> ===
 
=== <code>owner</code> ===
  owner [read-only Entity]
+
  '''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.
+
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>energy</code> ===
+
=== <code>position</code> ===
  energy [read-write double]
+
  '''position''' : [[Oolite JavaScript Reference: Vector|Vector]] (read/write)
The entity’s total energy; ranges from 0 to <code>[[#maxEnergy|maxEnergy]]</code>.
 
  
=== <code>maxEnergy</code> ===
+
=== <code>scanClass</code> ===
  maxEnergy [read-only double]
+
  '''scanClass''' : String (read-only)
The highest permissible value of <code>[[#energy|energy]]</code>.
+
The entity's current [[Shipdata.plist#scan_class|scan class]] such as <code>"CLASS_NEUTRAL"</code> or <code>"CLASS_CARGO"</code>, etc.
  
== Methods ==
+
In 1.77 or later, this is partially read/write for Ship entities other than the PlayerShip.
=== <code>setPosition</code> ===
 
void setPosition([[Oolite/Development/Scripting/Class/Vector#Vector Expressions|vectorExpression]])
 
Instantaneously move the entity to the specified position.
 
  
=== <code>setOrientation</code> ===
+
=== <code>spawnTime</code> ===
  void setOrientation([[Oolite/Development/Scripting/Class/Quaternion#Quaternion Expressions|quaternionExpression]])
+
  '''spawnTime''' : Number (read-only)
Instantaneously rotate the entity to the specified orientation.
+
The time at which the entity came into existence.
  
 +
=== <code>status</code> ===
 +
'''status''' : String (read-only)
 +
The entity's current status. Possible values (though not an exhaustive list):
 +
* <code>"STATUS_DOCKED"</code>
 +
* <code>"STATUS_LAUNCHING"</code>
 +
* <code>"STATUS_IN_FLIGHT"</code>
 +
* <code>"STATUS_WITCHSPACE_COUNTDOWN"</code>
 +
* <code>"STATUS_EXITING_WITCHSPACE"</code>
 +
* <code>"STATUS_BEING_SCOOPED"</code>
  
[[Category:Oolite scripting]] [[Category:Oolite Development]]
+
[[Category:Oolite JavaScript Reference]]

Latest revision as of 00:24, 28 October 2022

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.

isSunlit

This property was added in Oolite test release 1.89.

isSunlit : Boolean (read-only)

true if the entity is a currently being lit by the sun or false if in the shadow of another entity, like a planet or station.

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 entity's current scan class such as "CLASS_NEUTRAL" or "CLASS_CARGO", etc.

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 entity's current status. Possible values (though not an exhaustive list):

  • "STATUS_DOCKED"
  • "STATUS_LAUNCHING"
  • "STATUS_IN_FLIGHT"
  • "STATUS_WITCHSPACE_COUNTDOWN"
  • "STATUS_EXITING_WITCHSPACE"
  • "STATUS_BEING_SCOOPED"