HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

event natives and boolexpr

09-21-2007, 07:16 AM#1
StRoNgFoE_2000
Collapse JASS:
native TriggerRegisterPlayerUnitEvent takes trigger whichTrigger, player whichPlayer, playerunitevent whichPlayerUnitEvent, boolexpr filter returns event

Since most events like this one take a boolexpr, does this mean I can put my trigger condition in there? I'd test it myself but at the moment I'm swamped with things to do (going through all my code removing all locations and replacing with coords.. headache!)

Edit.. ill post a small example..

Collapse JASS:
// -- instead of this...
    call TriggerRegisterPlayerUnitEvent(gg_trg_Upgrade, p, EVENT_PLAYER_UNIT_RESEARCH_START, null)
    call TriggerAddCondition(gg_trg_Upgrade, Condition(function UpgradeCond))
// -- use this...
    call TriggerRegisterPlayerUnitEvent(gg_trg_Upgrade, p, EVENT_PLAYER_UNIT_RESEARCH_START, Condition(function UpgradeCond))

It looks like it would work, but will it give the same effect if it does?
09-21-2007, 07:55 AM#2
Silvenon
You know, that slipped my mind too! But I have never tested, it would be cool if you can do that......
09-21-2007, 10:56 AM#3
Hitchhiker
I think that they are different because the event requires a filter boolexpr so you would have to use GetFilterUnit() and GetTriggerUnit() returns null ( not sure on this).
09-22-2007, 09:35 PM#4
PitzerMike
Collapse JASS:
call TriggerRegisterPlayerUnitEvent(gg_trg_Upgrade, p, EVENT_PLAYER_UNIT_RESEARCH_START, Filter(function UpgradeCond))

Fixed. Not that Condition vs. Filter really makes a difference though. You'd also use GetFilterUnit instead of triggering unit in the callback.
Works, might even cause a slight speed gain ...
09-22-2007, 10:10 PM#5
TaintedReality
Are you sure that that condition isn't filtering the units for which the event is added? By that I mean, you can have that condition be that a unit's health is above 100. Then it goes through all units for player p whose health is 100, and adds an event to the trigger for when that unit starts research. However, when the units actually start research it doesn't care what their health is, and the trigger doesn't fire for any units who didn't have >100 health when the trigger was created.

I'm skeptical that it would behave as conditions do, and you'll also notice that a boolexpr parameter doesn't even exist on the TriggerRegisterUnitEvent. If it fits with what I'm saying, then that is because there's no reason to filter because only one unit is being considered.

Of course, I have no idea if I'm right or not :). I've never tried it.
09-22-2007, 10:15 PM#6
Hitchhiker
hm just tested it and it didnt work...
Collapse JASS:
function Cond takes nothing returns boolean
    call BJDebugMsg("Condition...")
    return false
endfunction

function Action takes nothing returns nothing
    call BJDebugMsg("Action...")
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerAddAction(t, function Action)
    call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_RESEARCH_START, Filter(function Cond))
endfunction
showed "Action..." while
Collapse JASS:
function Cond takes nothing returns boolean
    call BJDebugMsg("Condition...")
    return false
endfunction

function Action takes nothing returns nothing
    call BJDebugMsg("Action...")
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()

    call TriggerAddAction(t, function Action)
    call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_RESEARCH_START, null)
    call TriggerAddCondition(t, Condition(function Cond))
showed "Condition..." when starting to research something.
09-22-2007, 10:20 PM#7
TaintedReality
Hmm. Sounds like I must have been wrong too then =P.
09-22-2007, 11:04 PM#8
Hitchhiker
When using EVENT_PLAYER_UNIT_DEATH it works...
seems that the filter doesnt apply to all event types.

But remember that every GetTriggerXXX (GetTriggeringTrigger(), GetTriggerUnit(),...) doesnt work in Filters, only GetFilterXXX works.