Set
Sets a local or global variable to a specified value. This value can be a number or an expression.
Arithmetic Operators:
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus (do integer division and return remainder) |
Notes:
When using only numbers in the calculation, you need to use at least one decimal point to tell the game that you want to use floating point division, without a decimal point the remainder is truncated at the end of the division:
float a set a to 9/5 ; will set "a" to 1.000 set a to 9.0/5 ; will set "a" to 1.800
When your variable is an integer and you want the result to be rounded you need to use a decimal point in the division and add 0.5:
short a set a to 9/5 ; will set "a" to 1 set a to 9/5 + 0.5 ; will set "a" to 1 set a to 9.0/5 ; will set "a" to 1 set a to 9.0/5 + 0.5 ; will set "a" to 2 set a to 7.0/5 + 0.5 ; will set "a" to 1
Examples:
set a to 2 set b to a*a set c to (b - a)*b - a set d to ((3* -b+a) - c)/ -2 message "a=%.0f, b=%.0f, c=%.0f, d=%.0f" a b c d ; ("a=2, b=4, c=6, d=8") set stage to getstage quest1 + 10
As you see, when you put a minus right in front of a variable the variable will be negated. To acomplish this, the parser needs you to put spaces around all minuses that are operators and not algebraic signs. If you use "b-a" in the above example, the script doesn't compile; it needs to be "b - a".