• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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