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

View
 

command_set_variable

Page history last edited by Dave Thaler 3 years, 6 months ago Saved with comment

The set_variable mission scripting command makes or sets a named value.  There are three forms of this command.

 

To set a value to a constant:

Attribute

Valid Values

Optional?

Description

name

text

 

Name of the variable to set. 

value

big negative number to big positive number

 

Value to set the variable to.

integer yes or no yes - defaults to "no" Sets variable type to integer or floating point

 

To set a value to a random integer value:

Attribute

Valid Values

Optional?

Description

name

text

 

Name of the variable to set. 

randomIntHigh

number

 

Artemis can generate random integers only within a range of at most 32768.  So if randomIntLow is 0, then the highest integer it can generate is 32767 even if randomIntHigh is higher.   Similarly if randomIntLow is 10000, then the highest integer it can generate is 42767.

randomIntLow

number lower than randomIntHigh

 

 

integer yes or no yes - defaults to "no"  

 

To set a value to a random floating-point value:

Attribute

Valid Values

Optional?

Description

name

text

 

Name of the variable to set.  

randomFloatHigh

number

 

 

randomFloatLow

number lower than randomFloatHigh

 

 

 

The "integer" attribute must be set in the start event, or before the variable is tested with "if_variable". If it is not, the variable will be set to floating point automatically. An integer variable can be set to any integer value, and if set to a floating point value, it will be truncated. A floating point value can be set to any value.

 

Values are first read into a 32-bit floating point number, and then converted to an integer if the "integer" attribute is set.  This means that for very large positive or negative numbers, some precision is lost.  For example, trying to set a variable to "2147483000" actually results in it getting the value 2147483008 for an integer variable or 2147483008.0 for a floating point variable, since that is the closest number that can be represented in a 32-bit floating point number.  Similarly, "-2147483000" results in -2147483008. 

 

It also means that fractional floating point values generally cannot be represented exactly.  For example, "0.2" results in 0.2000000030. For this reason, testing a floating point value with "if_variable" using the comparator "EQUALS" may result in an improper result if the value is not an integer value. It is recommended that floating point values be compared by using a combination of "LESS_THAN" and "GREATER_THAN" with a small floating point value (such as 0.1) to ensure it is within a small range around the desired value.

 

A handy converter to observe what values can be represented is online at https://www.h-schmidt.net/FloatConverter/IEEE754.html

 

Comments (0)

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