Difference between revisions of "Set"

168 bytes added ,  13:44, 17 April 2006
m
no edit summary
imported>JOG
m
imported>JOG
m
Line 27: Line 27:
'''Notes:'''
'''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:
*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
  float a
  set a to 9/5    ; will set "a" to 1.000
  set a to 9/5    ; will set "a" to 1.000
  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 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:  
*When you want to store the correctly rounded result of a division in an integer-variable, you need to make sure the calculation uses floating poing (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
  set a to 9/5  + 0.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        ; will set "a" to 1
  set a to 9.0/5 + 0.5  ; will set "a" to '''2'''
  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'''
  set a to 7.0/5 + 0.5  ; will set "a" to '''1'''


short a
float b
set b to 9
set a to b/5  + 0.5  ; will set "a" to '''2'''


'''''Examples:'''''  
 
'''''Other Examples:'''''  
  set a to 2
  set a to 2
  set b to a*a
  set b to a*a
Line 50: Line 57:
   
   
  set stage to getstage quest1 + 10
  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".


[[Category:Commands]]
[[Category:Commands]]
Anonymous user