Difference between revisions of "Oolite JavaScript Reference: Entity"
(→Methods: Clarified replacements for setOrientation()/setPosition().) |
(→status) |
||
(24 intermediate revisions by 7 users not shown) | |||
Line 2: | Line 2: | ||
<small>'''Subtypes:''' <code>[[Oolite JavaScript Reference: Planet|Planet]]</code>, <code>[[Oolite JavaScript Reference: Ship|Ship]]</code>, <code>[[Oolite JavaScript Reference: Sun|Sun]]</code></small> |
<small>'''Subtypes:''' <code>[[Oolite JavaScript Reference: Planet|Planet]]</code>, <code>[[Oolite JavaScript Reference: Ship|Ship]]</code>, <code>[[Oolite JavaScript Reference: Sun|Sun]]</code></small> |
||
− | {{Oolite-class-added|1.70}} |
||
+ | 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. |
||
− | |||
− | The '''<code>Entity</code>''' class represents an object in the game universe. <code>[[Oolite JavaScript Reference: Vessel|Ship]]</code>s, <code>[[Oolite JavaScript Reference: Station|Station]]</code>s, <code>[[Oolite JavaScript Reference: Planet|Planet]]</code>s and the <code>[[Oolite JavaScript Reference: Player|Player]]</code>are types of entity. Note that these more specific types have additional properties and methods. |
||
=== Stale References === |
=== Stale References === |
||
− | 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>[[# |
+ | 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 == |
|
− | + | === <code>collisionRadius</code> === |
|
+ | '''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. |
||
− | == Properties == |
||
=== <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 |
+ | 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 27: | Line 24: | ||
<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> |
+ | === <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> |
+ | === <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>maxEnergy</code> === |
||
− | '''maxEnergy''' : Number (read-only) |
||
− | The highest permissible value of <code>[[#energy|energy]]</code>. |
||
− | |||
− | === <code>orientation</code> === |
||
− | '''orientation''' : [[Oolite JavaScript Reference: Quaternion|Quaternion]] (read-only) |
||
− | The spacial orientation of the entity. |
||
− | |||
− | '''See Also:''' <code>[[#setOrientation|setOrientation]]()</code> |
||
− | |||
− | === <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 a missile, the ship that launched it. There may be other uses. |
||
− | |||
− | === <code>position</code> === |
||
− | '''position''' : [[Oolite JavaScript Reference: Vector|Vector]] (read-only) |
||
− | The position of the entity in system co-ordinates. |
||
− | |||
− | '''See Also:''' <code>[[#setPosition|setPosition]]()</code> |
||
− | |||
− | === <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 43: | Line 40: | ||
=== <code>isPlayer</code> === |
=== <code>isPlayer</code> === |
||
'''isPlayer''' : Boolean (read-only) |
'''isPlayer''' : Boolean (read-only) |
||
− | <code>true</code> if the entity is the [[Oolite JavaScript Reference: |
+ | <code>true</code> if the entity is the [[Oolite JavaScript Reference: PlayerShip|player ship]], <code>false</code> otherwise. |
=== <code>isShip</code> === |
=== <code>isShip</code> === |
||
Line 60: | Line 57: | ||
'''isSun''' : Boolean (read-only) |
'''isSun''' : Boolean (read-only) |
||
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Sun|Sun]], <code>false</code> otherwise. |
<code>true</code> if the entity is a [[Oolite JavaScript Reference: Sun|Sun]], <code>false</code> otherwise. |
||
+ | |||
+ | === <code>isSunlit</code> === |
||
+ | {{oolite-prop-added|1.89}} |
||
+ | '''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. |
||
=== <code>isValid</code> === |
=== <code>isValid</code> === |
||
Line 65: | Line 67: | ||
<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]]. |
||
− | == Methods == |
||
+ | === <code>isVisible</code> === |
||
− | === <code>call</code> === |
||
+ | {{Oolite-prop-added|1.77}} |
||
− | <div class="boilerplate metadata" id="oolite-scripting-change" style="margin: 0 5%; padding: 0 7px 7px 7px; background: #EDF1F1; border: 1px solid #999999; text-align: left; font-size:95%;"><small>Starting in Oolite test release '''1.72''', the <code>call()</code> method will only be available with the [[Debug OXP]] installed. Additionally, <code>call()</code> will only ever be available in test releases.</small></div> |
||
+ | '''isVisible''' : Boolean (read-only) |
||
− | function '''call'''(methodName : String, ...) |
||
+ | Determines if the entity is close enough to the player to be drawn. |
||
− | 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 <code>call()</code>, otherwise the result will be <code>undefined</code>. |
||
− | === <code> |
+ | === <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> |
+ | === <code>isWormhole</code> === |
− | {{Oolite- |
+ | {{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. |
|
− | == Static methods == |
||
+ | === <code>mass</code> === |
||
− | Static methods are methods which can be called on <code>Entity</code>, rather than an entity variable. Example: <code>var myEntity = Entity.entityWithID(142);</code> |
||
+ | '''mass''' : Number (read-only) |
||
− | === <code>entityWithID</code> === |
||
+ | The mass of the entity. Currently, this is directly proportional to the volume. |
||
− | {{Oolite-script-item-deprecated|method|1.74}} |
||
+ | |||
− | '''entityWithID'''(ID : Number (integer)) : Entity |
||
+ | === <code>maxEnergy</code> === |
||
− | Returns the entity with the specified [[#Universal IDs|universal ID]]. |
||
+ | '''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. Possible values (though not an exhaustive list): |
||
+ | * STATUS_IN_FLIGHT |
||
+ | * STATUS_BEING_SCOOPED |
||
+ | * STATUS_DOCKED |
||
+ | * STATUS_WITCHSPACE_COUNTDOWN |
||
+ | * STATUS_EXITING_WITCHSPACE |
||
− | [[Category:Oolite |
+ | [[Category:Oolite JavaScript Reference]] |
Latest revision as of 23:32, 4 July 2021
Prototype: Object
Subtypes: Planet
, Ship
, Sun
The Entity
class represents an object in the game universe. Ship
s, Station
s, Planet
s and Sun
s are types of entity. Note that these more specific types have additional properties and methods.
Contents
- 1 Stale References
- 2 Properties
- 2.1 collisionRadius
- 2.2 distanceTravelled
- 2.3 energy
- 2.4 heading
- 2.5 isDock
- 2.6 isInSpace
- 2.7 isPlanet
- 2.8 isPlayer
- 2.9 isShip
- 2.10 isStation
- 2.11 isSubEntity
- 2.12 isSun
- 2.13 isSunlit
- 2.14 isValid
- 2.15 isVisible
- 2.16 isVisualEffect
- 2.17 isWormhole
- 2.18 mass
- 2.19 maxEnergy
- 2.20 orientation
- 2.21 owner
- 2.22 position
- 2.23 scanClass
- 2.24 spawnTime
- 2.25 status
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 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. Possible values (though not an exhaustive list):
- STATUS_IN_FLIGHT
- STATUS_BEING_SCOOPED
- STATUS_DOCKED
- STATUS_WITCHSPACE_COUNTDOWN
- STATUS_EXITING_WITCHSPACE