• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Precedence in JASS

Level 11
Joined
Feb 18, 2004
Messages
394
Precedence in JASS

Definition of Precedence
In a programming language, the precedence of an operator determines in what order it will be evaluated. An operator with a higher precedence will be evaluated before another with a lower precedence. For instance multiplication has a higher precedence than addition.
http://www.google.ca/search?q=define:+precedence
The rules of precedence are important if you don’t want your code littered with needless parenthesis. JASS has only a few operators, so remembering their precedence is not so hard:

( )
not
* /
+ -
<= >= > < == !=
and or

The higher on the list, the higher an operators precedence. If two operators are in the same row, they share the same precedence and are thus executed from left-to-right. By this chart, the following examples are all true:

JASS:
a == b != c // Is the same as…
(a == b) != c

JASS:
a != b == c // Is the same as…
(a != b) == c

JASS:
1 + 2 * 3 – 4 / 2 // Is the same as…
1 + (2 * 3) – (4 / 2)

JASS:
false == 1 > 2 // This will fail to even compile, as it’s the same as…
(false == 1) > 2

JASS:
not 4 > 3 // This will also fail to compile, as it’s the same as…
(not 4) > 3

JASS:
a == b or c == d // Is the same as…
(a == b) or (c == d)


The or and the and operators are executed in a short circuit manner. This means that if from the current execution, an answer is determinate, execution stops. By this, the following are both true:

JASS:
f() // Returns false
t() // Returns true

t() or f() // f() will never be executed.

f() and t() // t() will never be executed.



Much credit to PurplePoot for helping me test precedence
Edit: Tiny formatting edit and removal of signature
 
Last edited:
Level 12
Joined
Aug 20, 2007
Messages
866
Uhhh, wait a second....

Does that mean if you have a function for converting indexes, only the first function will fire, bugging out your JASS???

Ex.
JASS:
udg_UnitArray[IndexFunction(u1)] == udg_UnitArray[IndexFunction(u2)]

Or maybe...

JASS:
udg_UnitArray[IndexFunction(u1)] == udg_UnitArray[IndexFunction(u2)] and udg_UnitArray[IndexFunction(u3)] == udg_UnitArray[IndexFunction(u4)]
 
Level 12
Joined
Aug 20, 2007
Messages
866
Ohhh, I gotcha, so if lets say it is an Or, and the first one is true, it will.... oh thats what the example means ><

So, if your second boolean function has some kind of unrelated call statement in there, you should be careful, because it will not always go through that secondary conditional function
 
Top