Difference between revisions of "Oolite JavaScript Reference: Equipment scripts"

From Elite Wiki
m
(activated)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Equipment scripts=
 
=Equipment scripts=
Equipment scripts are used to handle primable equipments activations.
+
Equipment scripts are used to handle primable equipment activations.
   
 
Attach to an equipment in the script property in [[equipment.plist]].
 
Attach to an equipment in the script property in [[equipment.plist]].
Line 14: Line 14:
 
}
 
}
   
Note the this variable points to the equipment script within this function and not to the worldScript regardless of the same js file is defined to be as worldscript also (which is not recommended).
+
Note the "this" variable points to the equipment script within this function and not to the worldScript regardless of the same .js file is defined to be worldscript also (which is not recommended).
   
 
An example to access a variable and call a function of your worldScript:
 
An example to access a variable and call a function of your worldScript:
Line 23: Line 23:
 
if( w._nameOfYourVariableInYourWorldScript )
 
if( w._nameOfYourVariableInYourWorldScript )
 
{
 
{
w._nameOfYourFunctionInYourWorldScript();
+
w._nameOfYourFunctionInYourWorldScript(w);
 
}
 
}
 
}
 
}
 
  +
The "w" variable is given to your function due to the "this" still points to the equipment script within the called function.
   
 
==mode==
 
==mode==

Latest revision as of 13:19, 15 May 2015

Equipment scripts

Equipment scripts are used to handle primable equipment activations.

Attach to an equipment in the script property in equipment.plist.


activated

This method is called when the player pressed the activate key (n) when this equipment is primed (Shift+N).

this.activated = function()
{
  // your code here
}

Note the "this" variable points to the equipment script within this function and not to the worldScript regardless of the same .js file is defined to be worldscript also (which is not recommended).

An example to access a variable and call a function of your worldScript:

this.activated = function()
{
  var w = worldScripts["nameOfYourWorldScript"];
  if( w._nameOfYourVariableInYourWorldScript ) 
  {
     w._nameOfYourFunctionInYourWorldScript(w);
  }
}

The "w" variable is given to your function due to the "this" still points to the equipment script within the called function.

mode

This method is called when the player pressed the mode key (b) when this equipment is primed (Shift+N).

this.mode = function()
{
  // your code here
}