Difference between revisions of "Set"
m
→Notes
imported>Speedo (Bug info) |
imported>UDUN m (→Notes) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Update}} | |||
Sets a local or global variable to a specified value. This value can be a number or an expression. | Sets a local or global variable to a specified value. This value can be a number or an expression. | ||
Line 26: | Line 27: | ||
==Notes== | ==Notes== | ||
*Improper syntax can cause scripts to stall myseriously, such as in the example below (the problem being the extra '134' at the end). | |||
set MyRefVar to SomeOtherRef 134 | |||
*The modulos operator "%" is evaluated after multiplication/division but before addition/subtraction | *The modulos operator "%" is evaluated after multiplication/division but before addition/subtraction | ||
4 * 3 % 2 = 0 | 4 * 3 % 2 = 0 | ||
Line 41: | Line 43: | ||
set a to 9.0/5 ; will set "a" to 1.800 | 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 | *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 point (so that the decimal-fraction isn't truncated) and add 0.5: | ||
short a | short a | ||
set a to 9/5 ; will set "a" to 1 | set a to 9/5 ; will set "a" to 1 | ||
Line 59: | Line 61: | ||
*You can also use a | *You can also use a comparison as the "value". The variable will then be set either to 1 or 0 depending on whether the condition is true or not. | ||
set goodluck to player.Getav luck > 60 | set goodluck to player.Getav luck > 60 | ||
Line 71: | Line 73: | ||
endif | endif | ||
You can use arithmetic operations on a | You can use arithmetic operations on a comparison value, but when you do so you need to put the comparison in parentheses: | ||
set luckbonus to 50*(player.Getav luck > 60) | set luckbonus to 50*(player.Getav luck > 60) |