Set
Revision as of 11:44, 17 April 2006 by imported>JOG
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) |
In integer divisions the remainder is truncated at the end of the operation:
set a to 9/5 ; will set "a" to 1 set a to 10*9/5 ; will set "a" to 18
To accomplish correct rounding in integer divisions you need to add 0.5:
set a to 9/5+0.5 ; will set "a" to 2 set a to 7/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".