Tutorial - Basic Triggering Efficiency
What is triggering efficiency?
Triggering efficiency is generally using fewer lines of code to perform the same task. This can reduce map size, lag, and waste-of-time syndrome.
An example of a very inefficient trigger:
Code:
E:
Unit enters Region<gen>
C:
(Triggering unit) equal to Unit 001<gen>
A:
Set LeakPoint = Position of (Triggering unit)
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Custom script: call RemoveLocation(udg_LeakPoint)
Why is this trigger inefficient? It doesn’t have any leaks.
This trigger is inefficient because you can do the same thing like this:
Code:
E:
Unit enters Region<gen>
C:
(Triggering unit) equal to Unit 001<gen>
A:
For every integer A from 1 to 7, do:
Set LeakPoint = Position of (Triggering unit)
Unit - Create 1 Footman at Leakpoint, facing Default Building Facing degrees
Custom script: call RemoveLocation(udg_LeakPoint)
Note how this trigger does the same thing as the previous one, but is much shorter. This is trigger efficiency.
Another example of trigger inefficiency is when you have several triggers with the same event, and similar conditions and actions. For example, if you have a folder of triggers for a dice roll, and one trigger for each possible roll, that is very inefficient. What would be better would be something like this:
Code:
E:
[Whatever activates the dice roll]
C:
A:
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 1
Then -
[Insert actions here]
Else -
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 2
Then -
[Insert actions here]
Else -
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 1
Then -
[Insert actions here]
Else -
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 3
Then -
[Insert actions here]
Else -
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 4
Then -
[Insert actions here]
Else -
If (All Conditions are true), then do (Then actions), else do (else actions)
If - (All conditions are true)
DiceRollInt equal to 5
Then -
[Insert actions here]
Else -
…
Although this is long, it is more efficient than having one trigger for each If/Then/Else statement.
More examples of trigger inefficiency are:
•Having several units stored in their own variables and then ordering them to do the same actions.
•Fixing leaks that do not exist.
•Having lines of code that essentially do nothing.
•
More to come…
The respective solutions to those problems are:
•Add the units to a unit group variable and order that unit group to do the actions.
•Make sure you know what leaks and what doesn’t
•Remove those lines of code.
•
More to come…
For questions or comments, please do not send me a PM. Post them in this thread.