Editing If

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 73: Line 73:
Note that "||" is evaluated before "&&": '''"||" has precedence over "&&"''', just like "*" is evaluated before "+" in normal algebra. Which also shows an opposite behaviour from the standard operator notations for scripting conditional expressions (IF statements), and needs to be clarified, as it impacts the design of '''boolean expressions''': in arithmetic and algebra, from the earliest use of mathematical notation, multiplication took precedence over addition, and the standard order of operators is: 1-exponents and roots; 2-multiplication and division; 3-addition and subtraction;
Note that "||" is evaluated before "&&": '''"||" has precedence over "&&"''', just like "*" is evaluated before "+" in normal algebra. Which also shows an opposite behaviour from the standard operator notations for scripting conditional expressions (IF statements), and needs to be clarified, as it impacts the design of '''boolean expressions''': in arithmetic and algebra, from the earliest use of mathematical notation, multiplication took precedence over addition, and the standard order of operators is: 1-exponents and roots; 2-multiplication and division; 3-addition and subtraction;
* In terms of computing, we're talking about a '''precedence number order''', and operator precedence is usually ordered with the corresponding number order. For expressions where two operators of different precedences compete for the same operand, the operator with the ''higher precedence'' wins.
* In terms of computing, we're talking about a '''precedence number order''', and operator precedence is usually ordered with the corresponding number order. For expressions where two operators of different precedences compete for the same operand, the operator with the ''higher precedence'' wins.
* '''functions have precedence over comparison and arithmetic operators, which themselves always have precedence over logical operators ("||" and "&&").'''
* '''functions have precedence over comparision and arithmetic operators, which themselves always have precedence over logical operators ("||" and "&&").'''
* In ''Common operator notation'' involving "normal" algebra or boolean algebra, "*" ("&&") is always evaluated before "+" ("||"), it has a higher precedence number than the "+" operator. For example, 3×4+5 = ((3×4)+5), not (3×(4+5)). Oblivion's scripting language keeps the normal precedence for arithmetic operations, '''but OR ("||") has a higher precedence than AND ("&&")''':<pre>if myVar1 == 1 && myVar2 == 1 || myVar2 == 5</pre>is equivalent to<pre>if myVar1 == 1 && (myVar2 == 1 || myVar2 == 5)</pre>This is true when MyVar1 = 1 AND myVar2 is either 1 or 5.<BR><BR>If you need the "&&" comparison operator to be evaluated before the "||" (OR) operator, you must include its part in-between parentheses. In this case: <pre>if (myVar1 == 1 && myVar2 == 1) || myVar2 == 5</pre>is true when either myVar2 is 5 OR both, myVar1 and myVar2 are 1.
* In ''Common operator notation'' involving "normal" algebra or boolean algebra, "*" ("&&") is always evaluated before "+" ("||"), it has a higher precedence number than the "+" operator. For example, 3×4+5 = ((3×4)+5), not (3×(4+5)). Oblivion's scripting language keeps the normal precedence for arithmetic operations, '''but OR ("||") has a higher precedence than AND ("&&")''':<pre>if myVar1 == 1 && myVar2 == 1 || myVar2 == 5</pre>is equivalent to<pre>if myVar1 == 1 && (myVar2 == 1 || myVar2 == 5)</pre>This is true when MyVar1 = 1 AND myVar2 is either 1 or 5.<BR><BR>If you need the "&&" comparision operator to be evaluated before the "||" (OR) operator, you must include its part in-between parentheses. In this case: <pre>if (myVar1 == 1 && myVar2 == 1) || myVar2 == 5</pre>is true when either myVar2 is 5 OR both, myVar1 and myVar2 are 1.


The later also explains why one has to be very careful in positioning conditions in a [[Logical Conditions#The_Condition_List|condition list]] of an editor item: for the CS/OB's engine, OR has order preference, ''has precedence'' over AND. For example, the condition items (A AND B OR C AND D) are evaluated as (A AND (B OR C) AND D), and not (( A AND B) OR (C AND D)), as opposed to common operator notation for most languages. In general, we call this an ''inversed'' or ''negative'' notation. '''Always keep the later in mind when [http://en.wikipedia.org/wiki/Boolean_algebra_%28logic%29#Basic_operations applying boolean algebra] for evaluating some given expression when scripting''', as standard operator notations will lead you to errors.
The later also explains why one has to be very careful in positioning conditions in a [[Logical Conditions#The_Condition_List|condition list]] of an editor item: for the CS/OB's engine, OR has order preference, ''has precedence'' over AND. For example, the condition items (A AND B OR C AND D) are evaluated as (A AND (B OR C) AND D), and not (( A AND B) OR (C AND D)), as opposed to common operator notation for most languages. In general, we call this an ''inversed'' or ''negative'' notation. '''Always keep the later in mind when [http://en.wikipedia.org/wiki/Boolean_algebra_%28logic%29#Basic_operations applying boolean algebra] for evaluating some given expression when scripting''', as standard operator notations will lead you to errors.

Please note that all contributions to the Oblivion ConstructionSet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see CSwiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)