Scripting Oolite with JavaScript

From Elite Wiki
Revision as of 01:37, 16 January 2007 by Dajt (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

JavaScript file format

To use JavaScript for an OXP, place a file script.js in the OXP's Config directory. Do not also include a script.plist or script.oos file.

script.js File Template

// Copy and paste this template into a file called script.js in the OXP Config directory
//
this.Name = "OXPName"
this.Descriptipn = "A description of what the OXP does."
this.Version = "1.0"

// You can copy and paste this function and just change the "Initialise"
// to another event name to handle other OXP events (eg "STATUS_DOCKED",
// "AlertConditionChanged", etc).
//
this.Initialise = function () {
    Log("Initialising OXP " + Name)
}

Scripting Events

The following events are available to OXP scripts written in JavaScript.

Initialise

The initialise event is called after all OXPs have been loaded. It can be used to do once-off initialisation such as registering to listen for certain keystrokes etc.

this.Initialise = function () {
}


KeyPressed

The KeyPressed event is called when a key the OXP is listening for has been pressed. It will be called once for each time the key is pressed, and will not be called again until the key is released and then pressed again.

The keycode argument gives the keycode of the key that was pressed. This can be used to determine which key was pressed if the OXP is listening for more than one key.

this.KeyPressed = function (keycode) {
}


AlertConditionChanged

The AlertConditionChanged event is called when the alert condition changes. The current alert condition can be read from Player.AlertCondition and the current alert flags can be read from Player.AlertFlags.

this.AlertConditionChanged = function (keycode) {
}


STATUS_DOCKED

The STATUS_DOCKED event is called periodically while the player is docked at a station or other entity with a docking port.

this.STATUS_DOCKED = function () {
}


STATUS_IN_FIGHT

The STATUS_IN_FIGHT event is called periodically while the player is flying in normal space or interstellar space (due to a misjump).

this.STATUS_IN_FIGHT = function () {
}


STATUS_LAUNCHING

The STATUS_LAUNCHING event is called once when the player has launched from a dock.

this.STATUS_LAUNCHING = function () {
}


STATUS_EXITING_WITCHSPACE

The STATUS_EXITING_WITCHSPACE event is called once when the player arrives in a new system.

this.STATUS_EXITING_WITCHSPACE = function () {
}