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

[Solved] trigger efficiency - what does it describe?

Status
Not open for further replies.
Level 8
Joined
Jan 8, 2010
Messages
493
it's not really a map question, but i want to know. 'cause it's quite bothering me.

i read somewhere something like how GUI users try on pushing efficiency. how is being efficient tackled when using JASS? is being efficient in GUI different from having trigger 1 instead of trigger 2, or not?


  • Events
    • Game - Every 1 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick Every Unit of Hero1 and do Actions
      • Unit - Kill (Picked Unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Integer Equal to 3
      • Then - Actions
        • Unit Group - Pick Every Unit of Hero2 and do Actions
          • Unit - Kill (Picked Unit)
        • Set Integer = 0
      • Else - Actions
        • Set Integer = Integer + 1



  • Events
    • Game - Every 1 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick Every Unit of Hero1 and do Actions
      • Unit - Kill (Picked Unit)
  • Events
    • Game - Every 3 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick Every Unit of Hero2 and do Actions
      • Unit - Kill (Picked Unit)
 
It depend on trigger actions you use,on problem you need to solve, in this case 1st trigger should be better but if then will create new function that will check condition so it will be more or less same thing.
Each trigger will be saved as global variable, but in case above you use integer so it's almost same etc etc etc.

Converted to vjass or just simple jass you can optimize this nicely and 1st trigger with only 1 timer should win.
 
Level 8
Joined
Jan 8, 2010
Messages
493
hmm. so it's the same even if i use 1 periodic timer with 2 if-then instead of, example, 3 periodic timer in GUI?

and that's the thing, i don't know JASS, so i don't know if being efficient in JASS means having less function calls (or is it what you call it) the same as a GUI having less triggers with more actions than more triggers with less actions.
 
Level 30
Joined
Jan 31, 2010
Messages
3,551
Here's a tip for you:

Whenever a trigger's event is detected, this uses up a small place in your... game stash.
In the same moment when such case is found, the conditions are being checked, one by one. More conditions you have, more place your trigger consumes. If the conditions are correct, then the actions are fired. When everything's over, then the trigger shuts down the ECAs (Events, Conditions & Actions), and frees up your memory. Every trigger uses, in simple approximation, about 20% for events, 30% for conditions, and rest (Warning, can be up to 250%, depending on trigger code length) for actions.

So, the solution shines: Using one longer trigger is better than two smaller ones. Basically, you can increase efficiency and reduce performance glitches by up to 50%.

Jass codes, as native custom scripts within usually only one trigger, can't bypass the limit of 200% from efficiency reduction (300 - 50 for ECs, -50 for custom scripts, not lined orders), and are easier to manage than hundreds of GUI triggers.

Hope this helps!
 
Hmm it's hard to discus about it without testing, but let me show you some examples that I'm sure about.
Maybe a little off topic but you should get the point.

  • example 1
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
or

  • example 2
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to True
        • Then - Actions
          • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
        • Else - Actions
They look same, but what's the catch?

First one will fire trigger and run it's actions only if dying unit is structure.
2nd trigger will always fire it's actions, for any unit type/class.

  • example 3
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to True
        • Then - Actions
          • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is A Hero) Equal to True
            • Then - Actions
              • Game - Victory Player 2 (Blue) (Show dialogs, Show scores)
            • Else - Actions
or

  • example 4
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to True
        • Then - Actions
          • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A Hero) Equal to True
        • Then - Actions
          • Game - Victory Player 2 (Blue) (Show dialogs, Show scores)
        • Else - Actions
These 2 again look same, but what's happening here?

First one will ignore 2nd if then else if it's condition equal to true. So if hero building die, it will never check things related to hero listed as actions in 2nd if.

2nd one will check both if the else functions even if first one equal to true or false.

----------------------------------

Now checking 1 if then (example 3) is faster than checking 2 (or more in example 4) but sometimes it can be useful.
Same for first, you can fire trigger action each time, but do some extra shit if some condition equal to true.

Think about it.
 
Level 8
Joined
Jan 8, 2010
Messages
493
@Apheraz
ah yeah. i was looking for something like how much memory such triggers consume, something like that, or how a single, longer trigger affects things than multiple, shorter ones.

@-Kobaz-
i understood what you mean. there really is a difference between a trigger firing without a condition and with a condition, and also the if-then-else branches. i used to do example 4 a lot, and when i noticed that there is a sometimes very slight lag in some test maps i made, i think having it in else's like example 3 is better.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • example 1
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
    • Actions
      • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
or

  • example 2
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A structure) Equal to True
        • Then - Actions
          • Game - Victory Player 1 (Red) (Show dialogs, Show scores)
        • Else - Actions
They look same, but what's the catch?

First one will fire trigger and run it's actions only if dying unit is structure.
2nd trigger will always fire it's actions, for any unit type/class.

Here are those trigs converted into jass with the editor's conversion function:
JASS:
function Trig_Untitled_Trigger_024_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_024_Actions takes nothing returns nothing
    call CustomVictoryBJ( Player(0), true, true )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_024 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_024 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_024, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_024, Condition( function Trig_Untitled_Trigger_024_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_024, function Trig_Untitled_Trigger_024_Actions )
endfunction

JASS:
function Trig_Untitled_Trigger_024_Copy_Func001C takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_024_Copy_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_024_Copy_Func001C() ) then
        call CustomVictoryBJ( Player(0), true, true )
    else
    endif
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_024_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_024_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_024_Copy, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Untitled_Trigger_024_Copy, function Trig_Untitled_Trigger_024_Copy_Actions )
endfunction

As you can see the functionality is almost the same.
 
Level 7
Joined
Sep 9, 2007
Messages
253
@ Ronojales: The thing you read recently might have been this thread.....
http://www.hiveworkshop.com/forums/...igger-efficiency-my-new-method-better-207914/


I'm guessing you learn about how triggers actually work behind the scenes when you start using JASS. I don't have the motivation to learn JASS at this stage so I must thank all of you for providing me with some further insight into GUI that you can only learn from using JASS.
 
Last edited:
Level 33
Joined
Mar 27, 2008
Messages
8,035
Type "/fps" while you're in-game of Warcraft III

Then, try run the first experiment and see its value, take the reading where it becomes constant (or nearly constant, adjusting about 5 ~ 10 points per seconds)

After that you restart the game (this time with another trigger, repeat the steps above)

Compare both reading

The reading that have higher value performs the best, it is actuall Frame Per Second, which if you have higher value of that, the game will become smoother.
 
Level 8
Joined
Jan 8, 2010
Messages
493
wait. there's really an "/fps" function in WC3??? :O

aside from emulators, the only game i had which i realized had that "/fps" function was Diablo 2. i never really bothered to try slash-something at WC3 'cause, well, cheats are all i had ever known to type in the chat command. that's plenty helpful :D
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
wait. there's really an "/fps" function in WC3??? :O

aside from emulators, the only game i had which i realized had that "/fps" function was Diablo 2. i never really bothered to try slash-something at WC3 'cause, well, cheats are all i had ever known to type in the chat command. that's plenty helpful :D

Did you ever know that diablo 2 characters can join warcraft 3 chat channels and vice versa?
And that almost all the chat commands are exactly the same?
Now you probably get the idea why the /fps works on both games ;)
 
Level 8
Joined
Jan 8, 2010
Messages
493
i knew for a time that both games can join either channels, or something to that effect. though i really never got myself wondering even once if there are slash-commands on WC3. and now i got to thinking if "!Hello" will place a "Hello" atop my hero's head :p

anyway, thanks for the info on /fps. that will really helped with my tests on triggers, as i usually connect having high fps to good triggering, aside from good visual effects (as lags usually means very low fps and/or buggy triggers).

oh, and this thread can be labeled solved too :)
 
Status
Not open for further replies.
Top