This wiki is a copy of the original Oblivion CS wiki created and maintained by the UESP.net. See CSwiki:Copy Notice for more info.

Difference between revisions of "If"

Jump to navigation Jump to search
29 bytes added ,  04:45, 17 April 2006
m
→‎Combining Comparisons: who said parantheses don't work?
imported>Gblues
(added info about logical operators being unaffected by parenthesis)
imported>JOG
m (→‎Combining Comparisons: who said parantheses don't work?)
Line 66: Line 66:
|}
|}


Note that while multiple logical operators can be used, the operators are always evaluated from left to right regardless of parentheses. For example:


<nowiki>if myVar1 == 1 && (myVar2 == 1 || myVar2 == 5)</nowiki>
Note that "||" is evaluated before "&&", just like "*" is evaluated before "+". in normal algebra.


Logically, this should say "if myVar is 1 AND myVar2 is either 1 or 5..." but in Oblivion, this will be evaluated as "if myVar is 1 AND myVar2 is 1, or if myVar2 is 5, ..." (thanks MaXiMiUS and JOG for testing this)
If you want the && to be evaluated first, you have to include that part in parentheses. For example:
 
<nowiki>if myVar1 == 1 && myVar2 == 1 || myVar2 == 5</nowiki>
 
This is true when MyVar1 = 1 AND myVar2 is either 1 or 5.
 
<nowiki>if (myVar1 == 1 && myVar2 == 1) || myVar2 == 5</nowiki>
 
This is true when either myVar2 is 5 OR both, myVar1 and myVar2 are 1


== Comparisons and Expressions ==
== Comparisons and Expressions ==
Anonymous user

Navigation menu