• 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] small question

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
Small question: is it better to use a condition to filter out possibles for a trigger event, or better to use a filter and avoid the condition altogether?
Feel free to point out any other improvements which might be made in these triggers.

JASS:
Version #1

function HeroesDeath_Condition01 takes nothing returns boolean
    local unit u        = GetDyingUnit ()
    local boolean b     = IsUnitIllusion (u) == false and IsUnitType (u, UNIT_TYPE_HERO)
//
    set u = null
    return b
endfunction

function HeroesDeath_Action01 takes nothing returns nothing
    local unit d     = GetDyingUnit ()
    local unit k     = GetKillingUnit ()
    x
    x
    x
    set d = null
    set k = null
endfunction

function InitTrig_HeroesDeath takes nothing returns nothing
    local integer q     = 0
    set gg_trg_HeroesDeath = CreateTrigger ()
    loop
        exitwhen q > 11
        call TriggerRegisterPlayerUnitEvent (gg_trg_HeroesDeath, Player (q), EVENT_PLAYER_UNIT_DEATH, null)
        set q = q + 1
    endloop
    call TriggerAddCondition (gg_trg_HeroesDeath, Condition (function HeroesDeath_Condition01))
    call TriggerAddAction (gg_trg_HeroesDeath, function HeroesDeath_Action01)
endfunction


Version #2

function HeroesDeath_Filter01 takes nothing returns boolean
    local unit u        = GetFilterUnit ()
    local boolean b     = IsUnitIllusion (u) == false and IsUnitType (u, UNIT_TYPE_HERO)
//
    set u = null
    return b
endfunction

function HeroesDeath_Action01 takes nothing returns nothing
    local unit d     = GetDyingUnit ()
    local unit k     = GetKillingUnit ()
    x
    x
    x
    set d = null
    set k = null
endfunction

function InitTrig_HeroesDeath takes nothing returns nothing
    local integer q     = 0
    set gg_trg_HeroesDeath = CreateTrigger ()
    loop
        exitwhen q > 11
        call TriggerRegisterPlayerUnitEvent (gg_trg_HeroesDeath, Player (q), EVENT_PLAYER_UNIT_DEATH, Filter (function HeroesDeath_Filter01))
        set q = q + 1
    endloop
    call TriggerAddAction (gg_trg_HeroesDeath, function HeroesDeath_Action01)
endfunction
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
[jass="Id rether this..."]function InitTrig_HeroesDeath takes nothing returns nothing
local integer q = 0
local filterfunc THISISFILTEEER = Filter (function HeroesDeath_Filter01)
set gg_trg_HeroesDeath = CreateTrigger ()
loop
exitwhen q > 11
call TriggerRegisterPlayerUnitEvent (gg_trg_HeroesDeath, Player (q), EVENT_PLAYER_UNIT_DEATH, THISISFILTEEER)
set q = q + 1
endloop
call TriggerAddAction (gg_trg_HeroesDeath, function HeroesDeath_Action01)
endfunction[/code]
 
Level 5
Joined
Oct 27, 2007
Messages
158
I would think there wouldn't be much of a difference between using a filterfunc within the event, or condition attached to the trigger, since they are basically the same thing, just declared differently..


I find the use of filters or conditions here useless. Look at the simple evaluation done (For structure/readability when there are loads of conditions to check, I can understand categorizing). This can easily be done in the actions itself, preventing a useless function call to either a filter callback or conditions check.

JASS:
Version #3
function HeroesDeath_Action01 takes nothing returns nothing
    local unit d = GetDyingUnit ()
    local unit k = GetKillingUnit ()

    if not IsUnitIllusion(d) and IsUnitType(d, UNIT_TYPE_HERO) then
        //Do your stuff here
    endif

    // If you hate if indenting check and return if false
    if IsUnitIllusion(d) and not IsUnitType(d, UNIT_TYPE_HERO) then
        return
    endif
    // Do your stuff here
    set d = null
    set k = null
endfunction

function InitTrig_HeroesDeath takes nothing returns nothing
    local integer q = 0

    set gg_trg_HeroesDeath = CreateTrigger ()
    loop
        exitwhen q > 11
        call TriggerRegisterPlayerUnitEvent (gg_trg_HeroesDeath, Player (q), EVENT_PLAYER_UNIT_DEATH, null)
        set q = q + 1
    endloop
    call TriggerAddAction (gg_trg_HeroesDeath, function HeroesDeath_Action01)
endfunction
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
@Drone: I dont agree with you because
not getting actions function executed at all would be better
 
Level 5
Joined
Oct 27, 2007
Messages
158
They are much faster though, which is important if you need speed in your map.


Explain to me how a condition/filter function can be faster than calling the actions code and doing the check there? Is this again another elaborate way of Blizzard coding I'm not aware of?

@Need_O2

Same goes for you, please explain the above.
 
Level 5
Joined
Oct 27, 2007
Messages
158
I suppose I'll use the filtered version. Do filterfunc's need to be nulled?

If the filter function is only temporarily used and is local, then you need to destroy and null it.

JASS:
call DestroyFilter(some_filterfunc)
set some_filterfunc = null
 
Level 5
Joined
Oct 27, 2007
Messages
158
Actions are threaded, conditions aren't, among other things.

Also, if your actions were to use any locals, they would have to be declared before evaluation.


Ok, that makes sense when you have a trigger that triggers a lot. However with a trigger that rarely triggers, I think you can get away with it in terms of speed.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Ive just figured out
Filtering Ability id doesnt work
you need to put as condition
Trigger filter fails
 
Level 5
Joined
Oct 27, 2007
Messages
158
If you have to check it in a filter function then you could also check for the unit's current order. Getting the order string of a unit's own ability works for GetFilterUnit()
 
Status
Not open for further replies.
Top