• 🏆 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!

[JASS] Can this be shortened??

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I read one tutorial (or i misinterpreted it) that you can use multiple conditions if you separate them with a comma. If this is so, can this be shortened??
Code:
function Trig_Max_Red_Func003001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'u008' )
endfunction

function Trig_Max_Red_Func003002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'nhem' )
endfunction

function Trig_Max_Red_Func003002002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'ohun' )
endfunction

function Trig_Max_Red_Func003002002002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'ushd' )
endfunction

function Trig_Max_Red_Func003002002002002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'n00O' )
endfunction

function Trig_Max_Red_Func003002002002002002001 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'efon' )
endfunction

function Trig_Max_Red_Func003002002002002002002 takes nothing returns boolean
    return ( GetUnitTypeId(GetTrainedUnit()) != 'ncer' )
endfunction

function Trig_Max_Red_Func003002002002002002 takes nothing returns boolean
    return GetBooleanOr( Trig_Max_Red_Func003002002002002002001(), Trig_Max_Red_Func003002002002002002002() )
endfunction

function Trig_Max_Red_Func003002002002002 takes nothing returns boolean
    return GetBooleanOr( Trig_Max_Red_Func003002002002002001(), Trig_Max_Red_Func003002002002002002() )
endfunction

function Trig_Max_Red_Func003002002002 takes nothing returns boolean
    return GetBooleanOr( Trig_Max_Red_Func003002002002001(), Trig_Max_Red_Func003002002002002() )
endfunction

function Trig_Max_Red_Func003002002 takes nothing returns boolean
    return GetBooleanOr( Trig_Max_Red_Func003002002001(), Trig_Max_Red_Func003002002002() )
endfunction

function Trig_Max_Red_Func003002 takes nothing returns boolean
    return GetBooleanOr( Trig_Max_Red_Func003002001(), Trig_Max_Red_Func003002002() )
endfunction

function Trig_Max_Red_Conditions takes nothing returns boolean
    if ( not GetBooleanOr( Trig_Max_Red_Func003001(), Trig_Max_Red_Func003002() ) ) then
        return false
    endif
    if ( not ( CountUnitsInGroup(GetUnitsOfPlayerAll(Player(10))) > 100 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Max_Red_Actions takes nothing returns nothing
    call KillUnit( GetTrainedUnit() )
endfunction

//===========================================================================
function InitTrig_Max_Red takes nothing returns nothing
    set gg_trg_Max_Red = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Max_Red, EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddCondition( gg_trg_Max_Red, Condition( function Trig_Max_Red_Conditions ) )
    call TriggerAddAction( gg_trg_Max_Red, function Trig_Max_Red_Actions )
endfunction

EDIT: I just converted GUI to custom, obviously.
 
Level 11
Joined
Feb 22, 2006
Messages
752
Jass has two boolean operators besides the == (equal to) operator that can operate on booleans (>, <, >=, <=, != only work on numerical types):

  • and
  • or

EDIT: Jass also has the operator NOT, which basically flips the boolean (if true, then return false; if false, then return true)

so instead of

JASS:
function func_01 takes nothing returns boolean
    return true
endfunction

function func_02 takes nothing returns boolean
    return false
endfunction

function conditions takes nothing returns boolean
    if ( GetBooleanOr( func_01(), func_02() ) ) then
        return true
    endif
    return false
endfunction

you could instead do:

JASS:
function conditions takes nothing returns boolean
    if ( func_01() or func_02() ) then
        return true
    endif
    return false
endfunction

or better yet:

JASS:
function conditions takes nothing returns boolean
    return ( func_01() or func_02() )
endfunction

and you can link as many booleans together with or's/and's as you want. However, if you mix the two, you need to think about which get evaluated first, as in that case order matters. To force certain ones to be evaluated first, just use parentheses.
 
Level 9
Joined
Jun 7, 2008
Messages
440
Well, when i converted the trigger. all of those where "or" already.
  • Events
  • Unit - A unit finishes training
  • Conditions
  • ((unit type of (trained unit)) not equal to (citizen_one ) or (((unit-type of (trained unit)) not equal to (citizen_2) // < I have 7 of these, all of them are the same.>
  • (Number of units in (Units owned by Player x (color) greater than or 100
  • Actions
  • Unit - Kill trained unit.
Does this still apply? I substituted "Red max" to "citizen_1" etc.
 
Level 5
Joined
Jan 6, 2006
Messages
106
Well, usually I use a dummy boolean for "or" functions. Every time an "or" condition is met then it changes the value of the dummy boolean. Finally, I add an "if" function for the dummy boolean to run my actions. This is useful if I have more than 2 "or" conditions to take account of.
 
Level 5
Joined
Jan 6, 2006
Messages
106
He means make one global boolean, then set it every time he needs a boolean value... but I don't see the point in that.

Oops, I NEVER use global booleans, I'll always make it local. Or, you may create a dummy unit and kill it as soon as one of the "or" conditions fail to meet. This method is basically quite the same as above, and it's more suited for JASS beginners.
 
Status
Not open for further replies.
Top