Difference between revisions of "Oolite JavaScript Reference: Global"

From Elite Wiki
(added reference to global methods & objects.)
 
(Properties)
Line 14: Line 14:
 
Returns the screen the player is looking at. If in flight, it's set to "GUI_SCREEN_MAIN".
 
Returns the screen the player is looking at. If in flight, it's set to "GUI_SCREEN_MAIN".
  
=== <code>mission</code> ===
+
=== <code>manifest</code> ===
 
  '''manifest''' : Object(read-only)
 
  '''manifest''' : Object(read-only)
 
This property allows an OXP to directly access the player ship's manifest properties.
 
This property allows an OXP to directly access the player ship's manifest properties.
Line 21: Line 21:
 
  '''mission''' : Object(read-only)
 
  '''mission''' : Object(read-only)
 
This property allows an OXP to access misson methods.
 
This property allows an OXP to access misson methods.
 +
 +
=== <code>missionVariables</code> ===
 +
'''missionVariables''' : Object(read-only)
 +
This property allows an OXP to access and modify misson variables, used to store information inside save game files.
  
 
=== <code>oolite</code> ===
 
=== <code>oolite</code> ===
Line 38: Line 42:
 
Also known as TAF. Will change the ratio between game real time and actual real time (default is 1). The accepted range is between 0.0625 (1/16) and 16. Attempting to set numbers outside this range will reset the TAF to 1.
 
Also known as TAF. Will change the ratio between game real time and actual real time (default is 1). The accepted range is between 0.0625 (1/16) and 16. Attempting to set numbers outside this range will reset the TAF to 1.
  
 +
=== <code>worldScripts</code> ===
 +
'''worldScripts''' : Object(read-only)
 +
This property allows an OXP to access all world scripts, their properties and functions.
 +
 +
'''Example:'''
 +
log(worldScripts['oolite-nova'].version);
  
 
== Methods ==
 
== Methods ==

Revision as of 11:36, 21 July 2010

The Global environment includes all Oolite objects and methods accessible by all scripts at all times.

Properties

clock

clock : Object(read-only)

This property allows an OXP to access the game clock's properties and methods.

galaxyNumber

galaxyNumber : Number(read-only)

Returns the number ot the galaxy the player is in.

guiScreen

guiScreen : String(read-only)

Returns the screen the player is looking at. If in flight, it's set to "GUI_SCREEN_MAIN".

manifest

manifest : Object(read-only)

This property allows an OXP to directly access the player ship's manifest properties.

mission

mission : Object(read-only)

This property allows an OXP to access misson methods.

missionVariables

missionVariables : Object(read-only)

This property allows an OXP to access and modify misson variables, used to store information inside save game files.

oolite

oolite : Object(read-only)

This property allows an OXP to access oolite's properties and methods.

player

player : Object(read-only)

This property allows an OXP to access the player object's properties and methods.

system

system : Object(read-only)

This property allows an OXP to access the current system's properties and methods.

timeAccelerationFactor

timeAccelerationFactor : Number(read/write)

Also known as TAF. Will change the ratio between game real time and actual real time (default is 1). The accepted range is between 0.0625 (1/16) and 16. Attempting to set numbers outside this range will reset the TAF to 1.

worldScripts

worldScripts : Object(read-only)

This property allows an OXP to access all world scripts, their properties and functions.

Example:

log(worldScripts['oolite-nova'].version);

Methods

displayNameForCommodity

function displayNameForCommodity(commodityName : String) 

Returns the display name corresponding to the specified commodity. Useful in conjunction with localisation OXPs, or expansions that rename commodities depending on which station / system the player is at.

expandDescription

function expandDescription(description : String [, locals : Object (Dictionary)]) : String

Expands a string, substituting special tokens and any key inside square brackets with the substitution rules for Communications. When local key/value pairs are provided, they take precedence over any other values. (buggy at the time of writing, fixed for 1.74.2 and later versions.)

Example:

expandDescription('My ball is [my_color].', { 'my_color': 'red' }); 

expandMissionText

function expandMissionText(textKey: String [, locals : Object (Dictionary)]) : String

Returns an expanded mission text, substituting any tokens and keys inside square brackets inside the original missiontext.plist value with its corresponding expanded string. If local key/value pairs are provided, they take precedence over any other values. (buggy at the time of writing, fixed for 1.74.2 and later versions.)

Example:

expandMissionText('oolite_trumble_title'); 

log

function log([messageClass : String ,] message : String)

Writes a message to Oolite's log. The optional messageClass can be used to specify which type of message is written to the log.

Example:

log('myOXP.init','MyOXP initialised and ready!');

randomInhabitantsDescription

function randomInhabitantsDescription([plural : boolean])

Returns a random capitalised word, suitable to describe one sentient being, or - if using the optional plural argument - a group of sentients.

Example:

player.consoleMessage("You'll meet a " +  randomInhabitantsDescription() +
                     ". She'll be with a group of " + randomInhabitantsDescription(true) +'.');

randomName

function randomName()

Returns a random capitalised word, suitable for use as name, or indeed surname.

Example:

player.consoleMessage(randomName() + ' ' + randomName() +' rules this system with an iron fist.');  

setScreenBackground

function setScreenBackground(image : String) 

Temporary override that sets the background of the current gui screen to the specified image. Override is lost after the player switches screens.

Example:

setScreenBackground('oolite-nova-system.png');

setScreenOverlay

function setScreenOverlay(image : String) 

Temporary override that sets the background of the current gui screen to the specified image. Override is lost after the player switches screens.

Example:

setScreenOverlay('trumblebox.png');