Difference between revisions of "Set"
Jump to navigation
Jump to search
imported>JOG m (another example) |
imported>JOG m (Example for set and functions) |
||
Line 61: | Line 61: | ||
set stage to getstage quest1 + 10 | set stage to getstage quest1 + 10 | ||
set weapondrawn to player.isweaponout | |||
[[Category:Commands]] | [[Category:Commands]] |
Revision as of 14:00, 6 May 2006
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:
- A minus right in front of a number or variable acts as "negative"-sign. When you want to do a subtraction, you need at least one space before and behind the minus. This is the only place where you really need a space between arithmetic operators. (For instance: "a-b" will not compile; it needs to be "a - b")
- When using only numbers in a division, 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 you want to store the correctly rounded result of a division in an integer-variable, you need to make sure, that the calculation uses floating poing (so that the decimal-fraction isn't truncated) 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
short a set a to 9 set a to a/5.0 + 0.5 ; will set "a" to 2
short a float b set b to 9 set a to b/5 + 0.5 ; will set "a" to 2
Other 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 set weapondrawn to player.isweaponout