HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Simple Question: TriggerRegister with filterfunc

01-21-2008, 08:18 PM#1
inkken
The function TriggerRegisterEnterRegion has, as one of its parameters, a boolexpr; or to be more exact, i'm using it as a filterfunc. I was wondering, exactly how does the boolexpr (filterfunc) work in terms of its relation to the TriggerRegisterEnterRegion?

Does it mean that when executing the function TriggerRegisterEnterRegion, the function will only register unit who successfully passed the filter? In other word, does it pick every unit and run them through the filterfunc; and if they pass the filterfunc, they will be register for the "unit enter region" event?

If so, what about newly created units; will they be checked against the filter?

I am not asking how a filterfunc works.
01-21-2008, 08:20 PM#2
Deaod
afaik the filterfunc checks the entering unit and if the unit passes those filters the actions added to the trigger will be executed.
01-21-2008, 08:24 PM#3
inkken
Quote:
Originally Posted by Deaod
afaik the filterfunc checks the entering unit and if the unit passes those filters the actions added to the trigger will be executed.

Wait, so it doesn't actually register the unit for the event beforehand?

So this would mean that, when a unit enters a region -- the filterfunc acts as a condition? And if the unit passes the filterfunct, a trigger is made and its action are added? Although, i don't see this can possibly work because if the registering occurs at the instance of the unit entering the region, where does the actual event detection occurs at? The unit is already in the region; it would have to re-enter, would it?
01-21-2008, 08:54 PM#4
Iron_Doors
Ive used it a few times and it seems as if it is exactly like a triggercondition with the exception that you can use only GetFilterUnit() in it and that it is evaluated before any of the triggers conditions. So you can do stuff like this:
Collapse JASS:
function RegisterUnit takes nothing returns boolean
    local unit u = GetFilterUnit()
    // everything here will be run whenever a unit enters
    // the region
    return false
endfunction
function init takes nothing returns nothing
    local trigger enterTrig = CreateTrigger()
    local region rectRegion = CreateRegion()
    call RegionAddRect( rectRegion, bj_mapInitialPlayableArea )
    call TriggerRegisterEnterRegion( enterTrig, rectRegion, Filter(function RegisterUnit))
    // no need to add an action or a condition since everything you could possibly want to do
    // you can do inside the filter function (RegisterUnit in this example)
endfunction

EDIT:
Quote:
Originally Posted by inkken
So this would mean that, when a unit enters a region -- the filterfunc acts as a condition?
True this far.
Quote:
Originally Posted by inkken
And if the unit passes the filterfunct, a trigger is made and its action are added?
Wrong. The trigger is made when you create it, and its actions are added when you use TriggerAddAction to add them.
Quote:
Originally Posted by inkken
Although, i don't see this can possibly work because if the registering occurs at the instance of the unit entering the region, where does the actual event detection occurs at?
You mixed something up here. The event detection i.e. when the event fires off, occurs at the instance of the unit entering the region. The event registering has taken place long ago when you used the actual TriggerRegister__ function.
Quote:
Originally Posted by inkken
The unit is already in the region; it would have to re-enter, would it?
No it doesnt.
01-21-2008, 09:20 PM#5
inkken
Interesting, +rep.

Quite an awkward behavior for a trigger register function.

After re-analyzing the function again:
Ok, i see what i misunderstood now. It makes perfect sense now.
:P god i feel like such a noob.