• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Question about 'if's

Status
Not open for further replies.
Well it depends. If you have two boolean expressions connected with a logical and
then the second one will be only evaluated if the first one returns true.

JASS:
if true and false then
    // both are evaluted
endif

if false and false then
    // first is evlauted
    // second is ignored
endif

So, it depends if IsUnitEnemy(u, p), or as you want to change it, if not IsUnitEnemy(u, p) will be true or false.
 

Rheiko

Spell Reviewer
Level 28
Joined
Aug 27, 2013
Messages
4,259
Even in language and reality, something that has "and" with them means both of them are necessary. (This is ignored most of the times though)
For example, "You and Her are summoned to attend the meeting".
It means both of them are summoned to attend the meeting, not just one of them.
If only one of them, that condition will not return true.
same goes with the if statement. Both conditions must be fulfilled for it to return true.
It takes both of the conditions into consideration before starting the actions of the other tasks.
 
Level 19
Joined
Dec 12, 2010
Messages
2,074
Even in language and reality, something that has "and" with them means both of them are necessary. (This is ignored most of the times though)
For example, "You and Her are summoned to attend the meeting".
It means both of them are summoned to attend the meeting, not just one of them.
If only one of them, that condition will not return true.
same goes with the if statement. Both conditions must be fulfilled for it to return true.
It takes both of the conditions into consideration before starting the actions of the other tasks.

don't apply human's logic with jass
false and true or true == false (jass)
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
if false and true then
!=
if true and false then

The point where this becomes interesting is:
if dothisandgivefeedback() and false then
vs
if false and dothisandgivefeedback() then

In fact, today I actually made use of this to skip a check that would fail because it would be missing from the object's fields by doing:
if ($isCustom || $widget->getRequest())
If you really want to use it is just user preference, but you should be aware of what happens in order to properly debug your code.
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
JASS is not a normal language. It lacks most common language features like bitwise operators and native modulus support.

It likely treats "and" and "or" as the same precedence level. It makes little difference anyway as one should be bracketing in such situations for readability.

Presented with...
A && B || C && D || E && F && G || H
Even knowing the precedence of the language (this example was C/C++) it is still confusing and can be error prone to modify as it is easy to make a mistake and modify the wrong group of terms. Imagine if the letters were large comparison terms. Imagine if there were 3 or 5 times as many terms.

Hence why it is often better for readability to bracket the terms...
(A && B) || (C && D) || (E && F && G) || H
There is absolutely no room for ambiguity if you do this.
 
Status
Not open for further replies.
Top