• 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] Learning Conditions

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
g'day fellow hivers. I got a question; is there a way to condense this and make it... well... neater?
JASS:
function Trig_Multiple_Check takes nothing returns boolean
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) == false ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_MECHANICAL) == false ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false ) ) then
        return false
    endif
    if ( not ( IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit())) == true ) ) then
        return false
    endif
    if ( not ( IsUnitDeadBJ(GetEnumUnit()) == false ) ) then
        return false
    endif
    if ( not ( IsUnitInGroup(GetEnumUnit(), udg_Temp_Group) == false ) ) then
        return false
    endif
    if ( not ( R2I(GetUnitStateSwap(UNIT_STATE_MAX_MANA, GetEnumUnit())) > 0 ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) == false ) ) then
        return false
    endif
    if ( not ( udg_Temp_Real < GetUnitStateSwap(UNIT_STATE_MANA, GetEnumUnit()) ) ) then
        return false
    endif
    return true
endfunction










I only ask because it always pop up when converting triggers with multiple conditions.
 
JASS:
if not (boolean) then
    return false
endif
return true
Translates to:
JASS:
return (boolean)

So you can either put all the conditions on one line, as in:
JASS:
return (boolean A) and (boolean B) and (boolean C)...
Or you can use comment delimiters to make it look nicer:
JASS:
return (boolean A) and /*
*/ (boolean B) and /*
*/ (boolean C) and /*
*/ (boolean D) // or however many times you need to

EDIT: Should be:
JASS:
function Trig_Multiple_Check takes nothing returns boolean
    return not IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) and /*
    */ not IsUnitType(GetEnumUnit(), UNIT_TYPE_MECHANICAL) and /*
    */ not IsUnitType(GetEnumUnit(), UNIT_TYPE_MAGIC_IMMUNE) and /*
    */ IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit())) and /*
    */ not IsUnitDeadBJ(GetEnumUnit()) and /*
    */ not IsUnitInGroup(GetEnumUnit(), udg_Temp_Group) and /*
    */ R2I(GetUnitStateSwap(UNIT_STATE_MAX_MANA, GetEnumUnit())) > 0 and /*
    */ not IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) and /*
    */ udg_Temp_Real < GetUnitStateSwap(UNIT_STATE_MANA, GetEnumUnit())
endfunction
I replaced == false with not, just a personal preference. All == true parts can just be removed.
 
Status
Not open for further replies.
Top