Difference between revisions of "Mission variable"

From Elite Wiki
(Categorised and respaced)
(Updating BB links)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Mission variables are states that can be set and queried by a script in [[scripts.plist]]
+
Mission variables are states that can be set and queried by a script in [[script.plist]], or any JavaScript script.
  
They should have a unique name that is ''always'' prefixed by '''mission_'''. A good naming scheme is to use '''mission_''' followed by a unique identifier for your script (for example, '''fredJamesMission1''' followed by an underscore then the use to which the variable is being put (for example, '''_counter1''' or '''_EnemyName'''.
+
They may be set to strings of characters that represent states (often in unspaced capital letters - just a style recommendation), or to numeric values, eg.
 +
 
 +
'''set: mission_myGreatMission_status START_OF_THE_MISSION'''
 +
// mission_myGreatMission_status will be set to the string 'START_OF_THE_MISSION'
 +
 +
'''set: mission_myGreatMission_rewardValue 105.5'''
 +
// mission_myGreatMission_rewardValue will be set to 105.5
 +
// I might alter this value before I award it as credits at the end of the mission
 +
 
 +
They should have a unique name that is ''always'' prefixed by '''mission_'''. A good naming scheme is to use '''mission_''' followed by a unique identifier for your script (for example, '''fredJamesMission1''') followed by an underscore followed by the use to which the variable is being put (for example, '''_counter1''' or '''_EnemyName''').
  
 
Mission variables are saved in the player's saved game file.
 
Mission variables are saved in the player's saved game file.
Line 7: Line 16:
 
=== Good Examples of Mission Variable Names ===
 
=== Good Examples of Mission Variable Names ===
  
  mission_fredJamesMission_counter1
+
  '''mission_fredJamesMission_counter1'''
 
  // might be set to a number that's incremented or decremented every so often
 
  // might be set to a number that's incremented or decremented every so often
 
   
 
   
  mission_trumbles_decisionKey
+
  '''mission_trumbles_decisionKey'''
 
  // could be the result of a missionChoice
 
  // could be the result of a missionChoice
 
   
 
   
  mission_moonShot_stage
+
  '''mission_moonShot_stage'''
 
  // could be a phrase describing the current scripted action eg. BEGINNING_MISSION or KILLING_ALIENS or MISSION_COMPLETE
 
  // could be a phrase describing the current scripted action eg. BEGINNING_MISSION or KILLING_ALIENS or MISSION_COMPLETE
  
 
=== Poor Examples of Mission Variable Names ===
 
=== Poor Examples of Mission Variable Names ===
  
  mission_counter
+
  '''mission_counter'''
 +
// no mission identifier
 
   
 
   
  mission_variable
+
  '''mission_variable'''
 
  // no mission identifier
 
  // no mission identifier
 
   
 
   
  mission_mymissionisaverycomplexaffairthatImightmisspell_andthisisanequallycomplexvariable
+
  '''mission_mymissionisaverycomplexaffairthatImightmisspell_andthisisanequallycomplexvariable'''
 
  // could be easily misspelt or misunderstood
 
  // could be easily misspelt or misunderstood
  
 +
=== JavaScript ===
 +
 +
In JavaScript, mission variables can be accessed through the [[Oolite_JavaScript_Reference:_Global#missionVariables|missionVariables global variable]]. In JavaScript, the '''mission_''' prefix is not used. Two equivalent examples:
 +
missionVariables.myGreatMission_status = "START_OF_THE_MISSION";
 +
missionVariables["myGreatMission_status"] = "START_OF_THE_MISSION";
 +
 +
== Links ==
 +
*[https://bb.oolite.space/viewtopic.php?f=4&t=18905 missionVariables and hasOwnProperty] (2017)
  
[[Category:OXP_howto]]
 
 
[[Category:Oolite]]
 
[[Category:Oolite]]
 +
[[Category:Oolite_scripting]]

Latest revision as of 02:10, 29 February 2024

Mission variables are states that can be set and queried by a script in script.plist, or any JavaScript script.

They may be set to strings of characters that represent states (often in unspaced capital letters - just a style recommendation), or to numeric values, eg.

set: mission_myGreatMission_status START_OF_THE_MISSION
// mission_myGreatMission_status will be set to the string 'START_OF_THE_MISSION'

set: mission_myGreatMission_rewardValue 105.5
// mission_myGreatMission_rewardValue will be set to 105.5
// I might alter this value before I award it as credits at the end of the mission

They should have a unique name that is always prefixed by mission_. A good naming scheme is to use mission_ followed by a unique identifier for your script (for example, fredJamesMission1) followed by an underscore followed by the use to which the variable is being put (for example, _counter1 or _EnemyName).

Mission variables are saved in the player's saved game file.

Good Examples of Mission Variable Names

mission_fredJamesMission_counter1
// might be set to a number that's incremented or decremented every so often

mission_trumbles_decisionKey
// could be the result of a missionChoice

mission_moonShot_stage
// could be a phrase describing the current scripted action eg. BEGINNING_MISSION or KILLING_ALIENS or MISSION_COMPLETE

Poor Examples of Mission Variable Names

mission_counter
// no mission identifier

mission_variable
// no mission identifier

mission_mymissionisaverycomplexaffairthatImightmisspell_andthisisanequallycomplexvariable
// could be easily misspelt or misunderstood

JavaScript

In JavaScript, mission variables can be accessed through the missionVariables global variable. In JavaScript, the mission_ prefix is not used. Two equivalent examples:

missionVariables.myGreatMission_status = "START_OF_THE_MISSION";
missionVariables["myGreatMission_status"] = "START_OF_THE_MISSION";

Links