[Solved] Game Performance: one trigger versus multiple.

Status
Not open for further replies.
Level 7
Joined
Jun 1, 2009
Messages
125
A little question about performance optimization.
What is better: create a separate trigger with it's own conditions for each case, or create one trigger with multiple If Then Else?

Example:
  • Example 1
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Round Equal to 1
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[1]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[2]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[3]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Round Equal to 2
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[1]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[2]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Dying unit)) Equal to Spawn_UnitType[3]
            • Then - Actions
              • -------- do some stuff --------
            • Else - Actions
              • Do nothing
        • Else - Actions
Does GUI trigger actually skip conditions check, if upper tier condition was false? (will example trigger keep checking UnitType, if Round variable won't match?)
What is better? Keep it as-is? Split on multiple separated triggers? Or both variants are equal?
Thank you for help!
 
I'm not sure about this, but I suspect that the difference is negligible in most cases, so I would go with whatever is more convenient.

Does GUI trigger actually skip conditions check, if upper tier condition was false?
Yes, if the condition evaluates to true, the Else actions will never be run, and vice versa.
 
Performance wise, the single body trigger approach would be more optimal to use than having multiple triggers. However, readability and maintainability would have to be sacrificed.

As for the conditional question, it will skip the unit type comparison if the condition is not true.

If you're going to keep this approach, you can have certain triggers execute when a certain condition is met in the single body trigger.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
If you're using Arrays then you might as well take advantage of For Loops to keep your code clean:
  • Example
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Round Equal to 1
        • Then - Actions
          • For each (Integer Dies_Int) from 1 to 3, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Triggering unit)) Equal to Spawn_UnitType[Dies_Int]
                • Then - Actions
                  • Trigger - Run Spawn_Trigger_R1[Dies_Int] (ignoring conditions)
                  • Skip remaining actions
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Round Equal to 2
            • Then - Actions
              • For each (Integer Dies_Int) from 1 to 3, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Triggering unit)) Equal to Spawn_UnitType[Dies_Int]
                    • Then - Actions
                      • Trigger - Run Spawn_Trigger_R2[Dies_Int] (ignoring conditions)
                      • Skip remaining actions
                    • Else - Actions
            • Else - Actions
And you'd assign these Spawn_Triggers to whatever Trigger you want to run like MyPad suggested:
  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Round 1 Death Triggers --------
      • Set VariableSet Spawn_Trigger_R1[1] = (This trigger)
      • Set VariableSet Spawn_Trigger_R1[2] = (This trigger)
      • Set VariableSet Spawn_Trigger_R1[3] = (This trigger)
      • -------- --------
      • -------- Round 2 Death Triggers --------
      • Set VariableSet Spawn_Trigger_R2[1] = (This trigger)
      • Set VariableSet Spawn_Trigger_R2[2] = (This trigger)
      • Set VariableSet Spawn_Trigger_R2[3] = (This trigger)
An even cleaner approach would be to use a Hashtable since this allows for multidimensional Arrays:
  • Setup Hash
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet Spawn_Hashtable = (Last created hashtable)
      • -------- --------
      • -------- Set RoundH = The Round that you want these variables to be assigned to: --------
      • Set VariableSet RoundH = 1
      • -------- Save the triggers that can run this Round: --------
      • Hashtable - Save Handle Of(This trigger) as 1 of RoundH in Spawn_Hashtable.
      • Hashtable - Save Handle Of(This trigger) as 2 of RoundH in Spawn_Hashtable.
      • Hashtable - Save Handle Of(This trigger) as 3 of RoundH in Spawn_Hashtable.
      • -------- --------
      • -------- Set RoundH = The Round that you want these variables to be assigned to: --------
      • Set VariableSet RoundH = 2
      • -------- Save the triggers that can run this Round: --------
      • Hashtable - Save Handle Of(This trigger) as 1 of RoundH in Spawn_Hashtable.
      • Hashtable - Save Handle Of(This trigger) as 2 of RoundH in Spawn_Hashtable.
      • Hashtable - Save Handle Of(This trigger) as 3 of RoundH in Spawn_Hashtable.
  • Death Hash
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
    • Conditions
    • Actions
      • For each (Integer Dies_Int) from 1 to 3, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Spawn_UnitType[Dies_Int]
            • Then - Actions
              • Trigger - Run (Load Dies_Int of Round in Spawn_Hashtable.) (ignoring conditions)
              • Skip remaining actions
            • Else - Actions
Also, "Do nothing" is unnecessary.
 

Attachments

  • Loops Arrays Hashtables example.w3m
    17.8 KB · Views: 30
Last edited:
Status
Not open for further replies.
Top