Oolite JavaScript Reference: Shipdata scripts

From Elite Wiki
Revision as of 12:34, 9 October 2009 by Pmw57 (talk | contribs) (Creating Shipdata scripts for JavaScript)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Oolite JavaScript Reference: Shipdata scripts

The shipdata.plist file can reference a JavaScipt script to perform behaviours that are executed on the creation or the disappearance of the ship.

This method was added in Oolite test release 1.71.

Assigning a script to shipdata.plist

The shipdata.plist file may be in one of two different formats: OpenStep or XML.

A script is assigned to an OpenStep shipdata.plist file in the following manner:

"my_custom_adder" = {
	name = "Freaky Turbo Trader";
	model = "custom_adder.dat";
	like_ship = "adder";
	roles = "trader my_freaky_adder";
	script = "myFreakyAdderTrader.js";
};

A script is assigned to an XML shipdata.plist file in the following manner:

<dict>
	<key>my_custom_adder</key>
	<dict>
		<key>name</key>
		<string>Freaky Turbo Trader</string>
		<key>model</key>
		<string>custom_adder.dat</string>
		<key>like_ship</key>
		<string>adder</string>
		<key>roles</key>
		<string>trader my_freaky_adder</string>
		<key>script</key>
		<string>myFreakyAdderTrader.js</string>
	</dict>
</dict>

JavaScript scripts takes precedence over all plist actions.

JavaScript actions

The following plist actions translate into javaScript in the following way:

Any other world script events can be applied to the ship as well.

JavaScript example for shipdata.plist scripts

Here is an example javaScript file that demonstrates where the .plist events occur

this.name        = "demo"; 
this.author      = "Paul Wilkins";
this.copyright   = "© 2009 Paul Wilkins";
this.description = "Empty script structure for shipdata.plist scripting"; 
this.version     = "0.0";

// setup_actions occur here

// launch_actions
this.shipSpawned = function () {
	// Put here your code for when a ship is created
};

// script_actions
this.shipDockedWithStation = function () {
	// Put here your code for when a ship docks with a station
};

// script_actions
this.shipWasScooped = function () {
	// Put here your code for when a ship is scooped
};

// death_actions
this.shipDied = function () {
	// Put here your code for when a ship dies
};