Knight7770
Hippopotomonstrosesquiped aliophobia
- Reaction score
- 187
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.What is triggering efficiency?
An example of a very inefficient trigger:
Code:
Events
Unit - A unit enters (Playable map area)
Conditions
Actions
Set LeakPoint = Center of (Playable map area)
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) 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:
Events
Unit - A unit enters (Playable map area)
Conditions
Actions
Set LeakPoint = (Center of (Playable map area))
Do Multiple ActionsFor each (Integer A) from 1 to 7, do (Actions)
Loop - Actions
Unit - Create 1 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) degrees
Custom script: call RemoveLocation(udg_LeakPoint)
Or,
Code:
Events
Unit - A unit enters (Playable map area)
Conditions
Actions
Set LeakPoint = (Center of (Playable map area))
Unit - Create 7 Footman for Player 1 (Red) at LeakPoint facing Default building facing (270.0) 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:
Events
Conditions
Actions
Do Multiple ActionsFor each (Integer A) from 1 to 6, do (Actions)
Loop - Actions
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
DiceRollInt Equal to (==) (Integer A)
Then - Actions
Else - Actions
So, if DiceRollInt equals 1, you do X actions, if it equals 2, do X actions, etc. Of course, this would not work in all instances; such as when you would need to do very different actions for each possible dice roll.
More on For every Integer A
The action For Every Integer A can be used for many, many things. For example, instead of having lines of the same code, just use For Every Integer A, and put that action in the loop; along with setting the number of times you want the action to occur.
Another example of For Every Integer A would be if you wanted to set an integer variable array to the same value for several parts of the array. You could use For Every Integer A to do that for you:
Code:
ASDF
Events
Conditions
Actions
Do Multiple ActionsFor each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
Set IntegerArray[(Integer A)] = 5
Code:
ASDF
Events
Conditions
Actions
Set IntegerArray[1] = 5
Set IntegerArray[2] = 5
Set IntegerArray[3] = 5
Set IntegerArray[4] = 5
Set IntegerArray[5] = 5
Set IntegerArray[6] = 5
Set IntegerArray[7] = 5
Set IntegerArray[8] = 5
Set IntegerArray[9] = 5
Set IntegerArray[10] = 5
For Every Integer B
If you need to have For Every Integer A loops inside of For Every Integer A loops, you cannot use For Every Integer A. Instead, you must use For Every Integer B. This would be better than having two separate triggers, and having one be run when the second (or third, etc.) For Every Integer A loop would be needed.
unneeded Variables
Sometimes, when working with variables, you can set some of those variables when you do not have to. An example of this:
Code:
Unit - Create 1 Footman at somewhere...
Set Dummy = (Last created unit)
Unit - Add 10 expiration timer to Dummy
Unit - Order Dummy to Attack (Triggering unit)
Code:
Unit - Create 1 Footman at somewhere...
Unit - Add 10 expiration timer to (Last created unit)
Unit - Order (Last created unit) to Attack (Triggering unit)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More examples of trigger inefficiency are:
•Having several units stored in their own variables and then ordering them to do the same actions.More examples of trigger inefficiency are:
•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.