Difference between revisions of "String expansion"

From Elite Wiki
m (What is switched)
m (When are things switched)
Line 7: Line 7:
 
= When are things switched =
 
= When are things switched =
 
Oolite calls only at certain places the switching routine.
 
Oolite calls only at certain places the switching routine.
*The most often used place is in [[missiontext.plist]]. In every text line the text between brackets is replaced by a variable or a [[descriptions.plist]] entry.
+
*The most often used place is in [[missiontext.plist]]. In every text line the text between brackets is replaced by a variable or a [[misc plists|descriptions.plist]] entry.
*Inside a [[descriptions.plist]] entry you can also use brackets. This way you can get a recursive process. Look for example in the description.plist inside Oolite were is generates random names in a recursive way.
+
*Inside a [[misc plists|descriptions.plist]] entry you can also use brackets. This way you can get a recursive process. Look for example in the description.plist inside Oolite were is generates random names in a recursive way.
 
*During evaluation of a AI.plist it only uses the switching on the content of a "commsMessage".
 
*During evaluation of a AI.plist it only uses the switching on the content of a "commsMessage".
 
*During evaluation of a [[script.plist]] all the lines in the DO part of a condition statement are switched. For some reason nothing is switched in the CONDITIONS part of a command so you can not use anything in brackets there.
 
*During evaluation of a [[script.plist]] all the lines in the DO part of a condition statement are switched. For some reason nothing is switched in the CONDITIONS part of a command so you can not use anything in brackets there.
Line 19: Line 19:
 
addSystemShips: my_ship 1 0.46
 
addSystemShips: my_ship 1 0.46
   
This line will then be executed and the ship is placed at the calculated random position. You can also define a [[description.plist]] entry of my_random_ship and define a list of several ships. When you then use:
+
This line will then be executed and the ship is placed at the calculated random position. You can also define a [[misc plists|description.plist]] entry of my_random_ship and define a list of several ships. When you then use:
 
addSystemShips: [my_random_ship] 1 0.[d100_number]
 
addSystemShips: [my_random_ship] 1 0.[d100_number]
 
the system will randomly pick a ship from the list and replace the d100_number for a value and returns the expanded string. This will than be excecuted.
 
the system will randomly pick a ship from the list and replace the d100_number for a value and returns the expanded string. This will than be excecuted.

Revision as of 20:37, 20 September 2007

Format

Oolite has a mechanism to replace text in strings by other text. At some places during script evaluation oolite searches for text between the square brackets []. If it finds this, it treats the text between the brackets a a kind of variable and tries to switch it, including the brackets fore the new text.

What is switched

If the text is a mission_variable or a local_variable, the content is replaced by the variable. If not it looks at the key's in the descriptions.plist. If it finds a match it uses one of the strings belonging to that key for switching.

When are things switched

Oolite calls only at certain places the switching routine.

  • The most often used place is in missiontext.plist. In every text line the text between brackets is replaced by a variable or a descriptions.plist entry.
  • Inside a descriptions.plist entry you can also use brackets. This way you can get a recursive process. Look for example in the description.plist inside Oolite were is generates random names in a recursive way.
  • During evaluation of a AI.plist it only uses the switching on the content of a "commsMessage".
  • During evaluation of a script.plist all the lines in the DO part of a condition statement are switched. For some reason nothing is switched in the CONDITIONS part of a command so you can not use anything in brackets there.

The way thing work means that you can create complicated structures. You can use for example:

addSystemShips: my_ship 1 0.[d100_number]

Oolite first offers above line to the replacement routine. That one replaces [d100_number] by a random number. e.g. 46. Than thje routine returns:

addSystemShips: my_ship 1 0.46

This line will then be executed and the ship is placed at the calculated random position. You can also define a description.plist entry of my_random_ship and define a list of several ships. When you then use:

addSystemShips: [my_random_ship] 1 0.[d100_number]

the system will randomly pick a ship from the list and replace the d100_number for a value and returns the expanded string. This will than be excecuted.