• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] event doesn't fire... why?

Status
Not open for further replies.
Level 3
Joined
Sep 11, 2008
Messages
58
Long version ;)

So far i never changed the functions that register the triggers, but while the script of my map becomes larger and larger and clarity becomes an issue, i thought i could start moving triggers to libraries and scopes and use local variables for the triggers. And this is what i changed in the below trigger, i set the variable to local, and i moved it to another place (the upmost 'code-space'). It's not even within a library or a scope yet, but it doesn't fire... I guess there's one more thing i didn't understand. But what?

Short version

Why doesn't the event fire?

JASS:
        function aActions2 takes nothing returns nothing
            call BJDebugMsg("action2")
            //call DialogDisplayBJ( true, glb_dMainmenu, GetTriggerPlayer() )
        endfunction
        
        function InitTrig_a takes nothing returns nothing
            local trigger trg = CreateTrigger(  )    
            
            call TriggerRegisterPlayerChatEvent( trg, Player(0), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(1), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(2), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(3), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(4), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(5), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(6), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(7), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(8), "-t", true )
            call TriggerRegisterPlayerChatEvent( trg, Player(9), "-t", true )
            call TriggerAddAction( trg, function aActions2 )
            
            //call DestroyTrigger(trg)
            //set trg = null
        endfunction

Thanks for any answers!

whisp
 
Level 3
Joined
Sep 11, 2008
Messages
58
me neither, but what i read so far it should be possible and shall only affect the possibility to start the trigger 'manually' (eg in another trigger).
 
Level 3
Joined
Sep 11, 2008
Messages
58
The trigger doesn't have a name, i moved it to the upmost in the trigger editor, to the part which has the map-name as name, the place where usually all the non-trigger code goes in. And i would like to put multiple triggers in there...
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
InitTrig_<blah> functions are only automatically run on map initialization if they are in a trigger called <blah>. In this case, that means your script should be in a trigger called a.

In other news, two things.

  • You don't need to null the trigger variable, and it won't work if you destroy it.
  • You can use a loop to reduce how long your event registration is to write;
    JASS:
    local integer i = 0
    loop
        exitwhen i > 9
        call TriggerRegisterPlayerChatEvent(trg,Player(i),true)
        set i = i + 1
    endloop
 
Level 3
Joined
Sep 11, 2008
Messages
58
Thanks for your answer. This clarified a lot for me concerning triggers. In that case I will call the function that registers the trigger from another function. I didn't know, that there can be triggers registered while the game is already running. This makes many things easier!

whisp
 
Level 3
Joined
Sep 11, 2008
Messages
58
Thanks again. I'd really like to use triggers dynamically. Thus i'm indeed interested in the details. Why are they a bad idea?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
  • Destroying a trigger that's running can cause really bad handle stack corruption.
  • They're a pain to manage in general.
  • They're unnecessary in all situations but to spread the few specific unit events which can't be (EVENT_UNIT_DAMAGED/ACQUIRED_TARGET/TARGET_IN_RANGE).
  • I imagine there's more here, but I haven't bothered to look into it since the above are enough reason not to use4 them.

So basically, they're risky if you mess up, annoying to manage, and in general unnecessary.
 
Level 3
Joined
Sep 11, 2008
Messages
58
Ok, i guess most of my triggers will be registered at map init anyways, just not directly, but from within another function that will be called on the at map init event. But still good to know that they could be registered at any point of the game and, if carefully managed, shouldn't cause any problems. Not that they are necessary, but it could be nice to have triggers registered within a struct.
 
Status
Not open for further replies.
Top