HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Filters in Timers

04-08-2009, 03:41 AM#1
Joker
I can't seem to figure out how to create a ally detection in a filter in a timer.

Collapse example:
scope Base initializer Init

    private struct asd
        unit blac
        group gg
        ...
        ..
        
        static method a takes ...
            set dat.blac = ...
            set dat.gg = CreateGroup()
            
            call SetTimerData( ... )  //Using TU
            call TimerStart( ... )
        endmethod
        
        private static method callback ...
            ...
            call GroupEnum...( g, ..., Condition( function asd.filter ) )
        endmethod
        
        private static method filter takes nothing returns boolean
            return ...//Here, how do you add in a ally detection?
        endfunction
    endstruct

    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == 'A000'
    endfunction

    private function Actions takes nothing returns nothing
        call asd.a(..)
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventEx( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, Condition( function Conditions ) )
        call TriggerAddAction( t, function Actions )
    endfunction

endscope
04-08-2009, 03:58 AM#2
ToukoAozaki
You can add a static variable to pass context information to the filter. Of course it will not collide with another instance. Alternatively, GetTimerData(GetExpiredTimer()) will work (but not recommended). This can happen because context is inherited in continuous child execution flow.


BTW you'll need to put your filter above the enum call.
04-08-2009, 04:10 AM#3
Joker
@You can add a static variable to pass context information to the filter.
Can I see an example?

@BTW you'll need to put your filter above the enum call.
JassHelper doesn't seem to care.
04-08-2009, 04:22 AM#4
azlier
Last I heard, methods below are called by either TriggerEvaluate or TriggerExecute (I forget, really).

By ally check, you mean checking whether the unit is a friend or not? IsUnitAlly should do the trick.
04-08-2009, 04:23 AM#5
Joker
@By ally check, you mean checking whether the unit is a friend or not? IsUnitAlly should do the trick.
Why do you try it yourself? What TWO units are you going to compare?
04-08-2009, 04:38 AM#6
FriendlyPsycho
You create temporary globals and use those globals in the filter function.
04-08-2009, 04:52 AM#7
Joker
@You create temporary globals and use those globals in the filter function.
Then I lose MUI support.
04-08-2009, 05:00 AM#8
FriendlyPsycho
Quote:
Originally Posted by FriendlyPsycho
You create temporary globals and use those globals in the filter function.

That's fully MUI.
04-08-2009, 01:52 PM#9
Vexorian
Quote:
Originally Posted by FriendlyPsycho
That's fully MUI.
It depends on circumstances, so it is half MUI.
04-10-2009, 03:51 PM#10
Joker
Any alternatives?
04-10-2009, 03:56 PM#11
ToukoAozaki
Quote:
Originally Posted by Joker
Can I see an example?
It's basically the same to what FriendlyPsycho said. Static variable is actually equivalent to a global.

Quote:
Originally Posted by Vexorian
It depends on circumstances, so it is half MUI.
In this particular GroupEnum case, I'm 100% sure that temp globals are no issue. Warcraft III seem to behave like single-threaded parser. In one execution context (and its childs), continuous exclusive execution is guaranteed unless halted by TriggerSleepAction or hitting op limit. This also explains why op limit exists; letting unlimited number of ops to run would definitely freeze the game.
04-10-2009, 08:15 PM#12
Anitarf
As long as the code in the GroupEnum callback doesn't cause any other triggers to run (for example, dealing damage in the group enum would cause damage detection triggers to run, which in turn could run another GroupEnum while this one is still running) it will be MUI. Even if there is a possibility of this happening you can still work around it by storing the previous value of the global in a local variable for the duration of the GroupEnum, something like this:

Collapse JASS:
    //...
    private static unit callbackU=null
    unit caster

    static method callback takes nothing returns nothing
        local unit u=callbackU
        set asd.callBackU=asd(GetTimerData(GetExpiredTimer())).caster
        call GroupEnum...( g, ..., Condition( function asd.filter ) )
        set asd.callbackU=u
        set u=null
    endmethod
04-10-2009, 09:24 PM#13
Joker
Thx Anit, that's what I needed. I can't seem to rep anyone since it logs me off when I try.