• 🏆 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!

Which trigger is executed first?

Status
Not open for further replies.
Let's say we have two triggers:

  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set Tempint = (Tempint + 1)
      • Game - Display to (All players) the text: (String(Tempint))
  • Untitled Trigger 002
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set Tempint = (Tempint - 1)
      • Game - Display to (All players) the text: (String(Tempint))
Initial value for Tempint is 0. It displays first 1 and then 0. What the criteria ordering triggers when encountering the same event and condition?
 
They run at the "same time" but one is compiled before the other. And that is determined just by whichever code is on top of the other. Let's take a look at an example map script:
JASS:
//***************************************************************************
//*
//*  Triggers
//*
//***************************************************************************

//===========================================================================
// Trigger: Funcx
//===========================================================================
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Funcx initializer Init
private function Initial takes nothing returns nothing
    call BJDebugMsg("Funcx")
endfunction
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,2,false)
    call TriggerAddAction(t,function Initial)
    set t = null
endfunction
endscope
//===========================================================================
// Trigger: Funcy
//===========================================================================
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Funcy initializer Init
private function Initial takes nothing returns nothing
    call BJDebugMsg("Funcy")
endfunction
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,2,false)
    call TriggerAddAction(t,function Initial)
    set t = null
endfunction
endscope
//===========================================================================
function InitCustomTriggers takes nothing returns nothing
    call InitTrig_Funcx(  )
    call InitTrig_Funcy(  )
endfunction

Basically, after 2 seconds it will display funcx and funcy. (These are two separate triggers, this is how the compiler lists them in the map's code) Funcx showed up first. The compiler reads from up to down, and thus whichever trigger is above the other is compiled first. (unless you use libraries and requires etc.)

The two will display at the same time (or at least with an unnoticeable difference), but the one above will be compiled first, to answer your question. =D
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
Once again, they work via a huge list of code to run when a certain event occurs.
They are all exectued on the same thread and one after each other. Dividing

2 triggers never run at the same time. One will always run before another.
This is because WC3 is single threaded. Meaning that only one chain of code can be executed at once.

Do not be foolled by it seeming to run instantly, as it does not. Remember that you can only view up to your screen refresh rate in frames per second. That means that as long as a trigger does not cause a frame to be skipped, it will be invisible to the player.
 
Status
Not open for further replies.
Top