| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Expression Evaluation

Page history last edited by Dave Thaler 6 years, 1 month ago Saved with comment

Starting with Version 1.69, literal number values have been replaced by an expression evaluator.  Put simply, anywhere you can type in a number, you can also type in a math expression like (5 * 2 / 6.554).  Most importantly, you can use variable names in the expressions, too.  All variable names are case-sensitive.

 

For example, these are all valid mission scripting commands:

    <set_variable name="ds38ZVAL" value="93000"/>

    <set_variable name="ds38ZVAL" value="9300*20 / 2"/>

    <set_variable name="ds38ZVAL" value="targetRange * (3000/2.55)"/>

 

You can use four usual - + * / operators, as well as ( ) parentheses. You cannot use ^, % or other operators.

 

Take note that variable names can consist of only numbers, and will be parsed before literals are.

Therefore, the following code will set the variable "var1" to 3, not the expected 125:

    <set_variable name="123" value="1"/>

    <set_variable name="var1" value="123+2"/>

 

However, even though variable names can also consist of only numbers and operators, such names will not be parsed before literals.

Therefore, the following code will set the variable "var1" to 4, not 9:

    <set_variable name="100/50" value="7"/>

    <set_variable name="var1" value="100/50+2"/>

 

Prior to Version 2.5.102, all scripting variables were integers, and assigning any floating point value would result in truncation to the next lowest integer.

Starting with Version 2.5.102, all scripting variables are instead assumed to be floating point unless expressly set. For example:

   <set_variable name="var10" value="2.55"/>

   <set_variable name="intstep" value="0" integer="yes"/>

 

Also starting with Version 2.5.102, all text in scripts comes with built-in variable formatting.  Any place in a script, like:

   <log text="This is text." />

can now have formatted variables placed inside them, using the 'escape' character, which is '|' in Version 2.5.104 and later (not '^' as mission-file-docs.txt claims, which was used prior to Version 2.5.104).  For example:

   <log text="This is text.  Variable Bob = |Bob|" />

Comments (2)

Starpathia said

at 2:31 pm on Jun 10, 2013

set_timer can also make use of the same syntax, so that you can make variable duration timers, or have specific mathematical formulas to set timers.

Starpathia said

at 3:18 pm on Jun 11, 2013

Attributes that expect strings instead of numbers do NOT support mathematical fomulas NOR variable substition.

For example, the create_object function's 'name' attribute will not accept variable substitution or mathematical functions. Therefore, in 1.702, object names are static strings and cannot be dynamically generated.

You don't have permission to comment on this page.