HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJASS: Dynamic triggers -> How to get triggering Trigger?

10-06-2009, 10:13 PM#1
XieLong
Okay guys, simple problem: I create some triggers during run time and within the trigger actions/conditions I would like to get the triggering trigger.
In fact my trigger actions/conditions are itself public static struct methods - which leads to the problem that GetTriggeringTrigger gives the wrong trigger...

Question: How do I get the _real_ triggering trigger, the one that was created by my code?
10-06-2009, 10:36 PM#2
Zerzax
Would setting the trigger to a global work? Then in that specific action you could know which global to reference.
10-06-2009, 10:43 PM#3
XieLong
As far as I see a global trigger is no alternative cause at compilation time it isn't known how many triggers will be created and used...
10-06-2009, 10:55 PM#4
peq
Just make sure you do not use the function/method above its declaration and it should not compile to a TriggerEvaluate call if I remember it right.

Why do you need Dynamic Triggers at all?
10-06-2009, 11:02 PM#5
Alevice
Quote:
Originally Posted by XieLong
Okay guys, simple problem: I create some triggers during run time and within the trigger actions/conditions I would like to get the triggering trigger.
In fact my trigger actions/conditions are itself public static struct methods - which leads to the problem that GetTriggeringTrigger gives the wrong trigger...

Why should it lead to the wrong trigger? Since tahts pretty much handled by the engine and not the language, you will always get the right trigger. Maybe it is you who think it might be wrong.
10-07-2009, 03:56 AM#6
TheKid
Could you post a snippet of the code, so I know what you mean? I can't really tell where you are trying to reference the trigger from.

Collapse JASS:
struct s_name
    
    static method onSpellEffectFilter takes nothing returns boolean
        local trigger t = GetTriggeringTrigger()    //* This is how you reference it, it works in both the conditions & actions functions
        set t = null
        
        return true
    endmethod
    
    static method onSpellEffect takes nothing returns nothing
        local trigger t = GetTriggeringTrigger()
        set t = null
    endmethod
    
    static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        call TriggerAddCondition(t, Filter(function s_name.onSpellEffectFilter))
        call TriggerAddAction(t, function s_name.onSpellEffect)
    endmethod
    
endstruct
10-07-2009, 06:28 AM#7
XieLong
Quote:
Originally Posted by peq
Just make sure you do not use the function/method above its declaration and it should not compile to a TriggerEvaluate call if I remember it right.
Thanks a lot that was the problem ^_^
10-07-2009, 08:17 PM#8
TheKid
What difference does it make if its TriggerEvaluate or not? You would still be able to reference GetTriggeringTrigger().
10-07-2009, 08:29 PM#9
Bobo_The_Kodo
@xombie

If vJass adds a triggerEvaluate in the middle (should throw compile error imo), it will return the dummy trigger that triggerEvaluate was called on, that the supposed trigger