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

[JASS] if multiple conditions ?

Status
Not open for further replies.
well i have an if condition but it has to check multiple conditions (all r units) any way to shorten this ?

JASS:
if ( GetTriggerUnit() == udg_Unit_Spawns_Red[1] or GetTriggerUnit() == udg_Unit_Spawns_Red[2] or GetTriggerUnit() == udg_Unit_Spawns_Red[3] or GetTriggerUnit() == udg_Unit_Spawns_Red[4] or GetTriggerUnit() == udg_Unit_Spawns_Red[5] or GetTriggerUnit() == udg_Unit_Spawns_Red[6] or GetTriggerUnit() == udg_Unit_Spawns_Red[7] or GetTriggerUnit() == udg_Unit_Spawns_Red[8] or GetTriggerUnit() == udg_Unit_Spawns_Red[9] or GetTriggerUnit() == udg_Unit_Spawns_Red[10] or GetTriggerUnit() == udg_Unit_Spawns_Red[11] or GetTriggerUnit() == udg_Unit_Spawns_Red[12] or GetTriggerUnit() == udg_Unit_Spawns_Red[13] or GetTriggerUnit() == udg_Unit_Spawns_Red[14] or GetTriggerUnit() == udg_Unit_Spawns_Red[15] or GetTriggerUnit() == udg_Unit_Spawns_Red[16] or GetTriggerUnit() == udg_Unit_Spawns_Red[17] or GetTriggerUnit() == udg_Unit_Spawns_Red[18] or GetTriggerUnit() == udg_Unit_Spawns_Red[19] or GetTriggerUnit() == udg_Unit_Spawns_Red[20] or GetTriggerUnit() == udg_Unit_Spawns_Red[21] or GetTriggerUnit() == udg_Unit_Spawns_Red[22] or GetTriggerUnit() == udg_Unit_Spawns_Red[23] or GetTriggerUnit() == udg_Unit_Spawns_Red[24] or GetTriggerUnit() == udg_Unit_Spawns_Red[25] or GetTriggerUnit() == udg_Boss_Unit_Player[1]) then

thanks for helping
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Okay after looking at your code again, the first way might be more efficient since you are doing a lot of conditions, and you only need one of them to be true.

JASS:
function CheckUnitSpawns takes unit u returns boolean
    local integer i = 1
    loop
        exitwhen i == 25
        if (GetTriggerUnit() == udg_Unit_Spawns_Red[i]) then
            //do nothing
        else
            return false
        endif
        set i = i +1
    endloop
    if (GetTriggerUnit() == udg_Boss_Unit_Player[1]) then
        //do nothing
    else
        return false
    endif
    return false
endfunction

I'm not 100% sure about the syntax, though. I'm still new at JASS myself and I'm not fully comfortable with multiple return statements.
 
Status
Not open for further replies.
Top