Difference between revisions of "Oolite JavaScript Reference: Ship scripts"
(Move to Ship scripts) |
m (Page moved.) |
||
| (11 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| + | =Ship scripts= | ||
| + | Ship scripts can be referenced from shipdata.plist to perform behaviours that are executed on the creation or the disappearance of the ship. | ||
| + | |||
| + | ==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 equivalents for shipdata actions== | ||
| + | |||
| + | The following shipdata.plist actions translate into javaScript in the following way: | ||
| + | |||
| + | * [[Shipdata.plist#setup_actions|setup_actions]] - are performed in JavaScript when the script is loaded | ||
| + | * [[Shipdata.plist#launch_actions|launch_actions]] - is handled as the [[Oolite JavaScript Reference: World script event handlers#shipSpawned|shipSpawned]] event | ||
| + | * [[Shipdata.plist#script_actions|script_actions]] - is handled as the [[Oolite JavaScript Reference: World script event handlers#shipDockedWithStation|shipDockedWithStation]] and [[Oolite JavaScript Reference: World script event handlers#shipWasScooped|shipWasScooped]] event | ||
| + | * [[Shipdata.plist#launch_actions|death_actions]] - is handled as the [[Oolite JavaScript Reference: World script event handlers#shipDied|shipDied]] event | ||
| + | |||
| + | Many other [[Oolite JavaScript Reference: World script event handlers|world script events]] can be applied to the ship as well. | ||
| + | |||
| + | ==JavaScript example for shipdata.plist scripts== | ||
| + | |||
| + | Here is a sample JavaScript file that demonstrates where the shipdata.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 | ||
| + | }; | ||
| + | |||
| + | See [[Oolite JavaScript Reference: Script]] for further scripting details. | ||
| + | |||
| + | [[Category:Oolite JavaScript Reference]] | ||
Latest revision as of 20:49, 16 January 2016
Contents
Ship scripts
Ship scripts can be referenced from shipdata.plist to perform behaviours that are executed on the creation or the disappearance of the ship.
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 equivalents for shipdata actions
The following shipdata.plist actions translate into javaScript in the following way:
- setup_actions - are performed in JavaScript when the script is loaded
- launch_actions - is handled as the shipSpawned event
- script_actions - is handled as the shipDockedWithStation and shipWasScooped event
- death_actions - is handled as the shipDied event
Many other world script events can be applied to the ship as well.
JavaScript example for shipdata.plist scripts
Here is a sample JavaScript file that demonstrates where the shipdata.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
};
See Oolite JavaScript Reference: Script for further scripting details.