• 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.

AND/OR in conditions?

Status
Not open for further replies.
Level 3
Joined
Sep 5, 2019
Messages
33
Hey all, Im just learning jass and am struggling to make a loop work. Im wondering if there can be 2 conditions for exitwhen?
using AND, or OR.

Example:
Function Fxn takes nothing returns nothing
local integer a = 1
local integer b = 5
loop
exitwhen a == 1 AND b == 1
set b = b-1
endloop
endfunction

I know its possible with other coding languages, and even found a tutorial on jass (Basic JASS Tips) that says it works. However, I cant make it work. This is the condition im trying to make work:
exitwhen ((udg_KeyLeftOn == false) OR (TimerGetRemaining(Reset) <= 0))

But Ive also tried much simpler ones, in loops, if/then statements, testing different placements of the parentheses and the OR itself, and different capitalization/lowercase of the OR. Ive also spent multiple hours looking for a thread or forum on this, and haven't found anything other than the tut above (which isn't clear enough for me apparently, since I cant make it work. I DO NOT HAVE vJass, which im beginning to think may be the problem. If anyone can tell me why this isnt working, or suggestions to fix it or a different way, Id appreciate it. I have thought about using a different function to set a global boolean variable to true if both conditions are true. If I cant figure this out, Ill just do that, even though it would be a bit slower, but mostly this is all because I want to understand jass better. Thank you!
 
Level 3
Joined
Sep 5, 2019
Messages
33
I downloaded vJass (btw, already love it, highlights in Editor, and I no longer have to comment out each line individually. Functions list, predictive type. Do i even need JassCraft anymore?? And iv only used it for 15 minutes.)
However, theres still a compiling error: Syntax Error unexpected: "OR"?
Same thing shows up for my super simple loop with OR, and for if/then statements.
 
Level 19
Joined
Oct 17, 2012
Messages
859
Yes, you can and you can even have multiple exitwhen's like so:
JASS:
       loop
            exitwhen udg_Spell_i_AutoAddTargets[i] and IsUnitInGroup(u, udg_Spell__TargetGroup)
            exitwhen not IsUnitInRangeLoc(u, udg_Spell__InRangePoint, udg_Spell__InRange)
            exitwhen not SpellFilterCompare(IsUnitType(u, UNIT_TYPE_DEAD), udg_Spell_i_AllowDead[i], udg_Spell_i_AllowLiving[i])
            exitwhen not SpellFilterCompare(IsUnitAlly(u, udg_Spell__CasterOwner), udg_Spell_i_AllowAlly[i], udg_Spell_i_AllowEnemy[i])
            exitwhen not SpellFilterCompare(IsUnitType(u, UNIT_TYPE_HERO) or IsUnitType(u, UNIT_TYPE_RESISTANT), udg_Spell_i_AllowHero[i], udg_Spell_i_AllowNonHero[i])
            exitwhen IsUnitType(u, UNIT_TYPE_STRUCTURE) and not udg_Spell_i_AllowStructure[i]
            exitwhen IsUnitType(u, UNIT_TYPE_FLYING) and not udg_Spell_i_AllowFlying[i]
            exitwhen IsUnitType(u, UNIT_TYPE_MECHANICAL) and not udg_Spell_i_AllowMechanical[i]
            exitwhen IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) and not udg_Spell_i_AllowMagicImmune[i]
            set udg_Spell__InRangeUnit = u
            //Run the user's designated filter, if one exists.
            exitwhen udg_Spell_i_InRangeFilter[i] != null and not TriggerEvaluate(udg_Spell_i_InRangeFilter[i])
            set j = j + 1
            set udg_Spell__InRangeUnits[j] = u
            exitwhen true
        endloop
 
Level 3
Joined
Sep 5, 2019
Messages
33
Thank you! The error isnt showing up any more, so I think its working (theres a few errors in vjass that werent in the regular editor, so Ill see if I can work those out).
Also, I didnt know you could have multiple exitwhens, and at different points in the loop? Thanks!
 
Status
Not open for further replies.
Top