1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Precedence in JASS

Discussion in 'JASS/AI Scripts Tutorials' started by Earth-Fury, Nov 21, 2007.

  1. Earth-Fury

    Earth-Fury

    Joined:
    Feb 18, 2004
    Messages:
    538
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    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:

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


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


    Code (vJASS):
    1 + 2 * 34 / 2 // Is the same as…
    1 + (2 * 3)(4 / 2)


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


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


    Code (vJASS):
    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:

    Code (vJASS):
    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: Feb 29, 2008
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    I never even knew this. =D

    Thanks.

    Seems good to me.
     
  3. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Really no reason not to approve this, IMO.

    ~Guess what?
     
  4. Herman

    Herman

    Joined:
    Aug 20, 2007
    Messages:
    877
    Resources:
    0
    Resources:
    0
    Woah, thats really useful to reference to

    +rep
     
  5. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    you have forgotten to write the t() and f() functions
    Else, nice to know but i think for my mental sanity (to keep the code easily readable) i will still use () ^^
     
    Last edited: May 4, 2008
  6. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Both will be executed, of course.
     
  7. Herman

    Herman

    Joined:
    Aug 20, 2007
    Messages:
    877
    Resources:
    0
    Resources:
    0
    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.
    Code (vJASS):
    udg_UnitArray[IndexFunction(u1)] == udg_UnitArray[IndexFunction(u2)]


    Or maybe...

    Code (vJASS):
    udg_UnitArray[IndexFunction(u1)] == udg_UnitArray[IndexFunction(u2)] and udg_UnitArray[IndexFunction(u3)] == udg_UnitArray[IndexFunction(u4)]
     
  8. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Ands and Ors are short circuit, meaning in any circumstance where the answer is known after one of the two booleans is evaluated, they will immediately finish execution.
     
  9. Herman

    Herman

    Joined:
    Aug 20, 2007
    Messages:
    877
    Resources:
    0
    Resources:
    0
    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
     
  10. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Yes, exactly.