Tutorial Basic Triggering Efficiency

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.

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
The longer version of that would be:
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)
Instead of setting Dummy to a variable, just do this:
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)
It will have the same effect, but with less lines of code.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
 

AgentPaper

From the depths, I come.
Reaction score
107
Needs a lot of work. The first part isn't bad, though it seems obvious. However, wouldn't it be more efficient to make 7 footmen in 1 action? On the second, I don't know what you're talking about much. Needs clarification and polish, and probably needs more added, maybe some more obscure methods for making triggers more efficient?
 

Mr.Tutorial

Hard in the Paint.
Reaction score
42
It only seems to touch up on one thing really "Integer 1-10" stuff. Why don't you use different triggers to show what "Integer" stuff can actually do. Get into detail, this could be explained much more deeply and efficiently.

Overall I rate: 5/10 :eek:. MORE DETAIL
 

U are a noob

Mega Super Ultra Cool Member
Reaction score
152
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)
You need to set the point before the loop and remove locations after the loop.
Code:
E: 
          Unit enters Region<gen>
C: 
          (Triggering unit) equal to Unit 001<gen>
A: 	         
           Set LeakPoint = Position of (Triggering unit)
           For every integer A from 1 to 7, do:

	         Unit - Create 1 Footman at Leakpoint, facing Default Building 	Facing degrees
           Custom script: call RemoveLocation(udg_LeakPoint)
 

vypur85

Hibernate
Reaction score
803
Code:
          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 -

This can also be shortened using Integer A loop (but it's very much depending on what you are doing - sometimes it's not possible).

Shortened version:
Code:
           For every integer A from 1 to 7, do:
                  If (All Conditions are true), then do (Then actions), else do (else actions)
	             If - (All conditions are true)
		        DiceRollInt equal to Integer A
	             Then -
	        	Unit - Kill Unit[Integer A]
                        Set Boolean[Integer A] = True
	             Else -
 

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
I updated the tutorial a bit :thup:
 

vypur85

Hibernate
Reaction score
803
Another suggestion:

In my experience, I usually see things in people trigger like

Code:
Unit - Create 1 Footman at somewhere...
[B]Set Dummy = (Last created unit)[/B]
Unit - Add 10 expiration timer to [B]Dummy[/B]
Unit - Order [B]Dummy[/B] to Attack (Triggering unit)

OR

Code:
Special Effect - Create special effect at Position of (Triggering unit) of type...
[B]Set Effect = (Last created Special Effect)[/B]
Special Effect - Destroy [B]Effect[/B]

The above variable settings are very much unnecessary. Maybe you should include those in your tutorial.

You should really consider to fix your tutorial in terms of neatness. Use real triggers instead of hand-typed ones. Fix appropriate code tags. Else this tutorial has nothing much special (quite a number of people will learn triggering efficiency on their own as they play along with triggers).
 

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
Another suggestion:

In my experience, I usually see things in people trigger like

Code:
Unit - Create 1 Footman at somewhere...
[B]Set Dummy = (Last created unit)[/B]
Unit - Add 10 expiration timer to [B]Dummy[/B]
Unit - Order [B]Dummy[/B] to Attack (Triggering unit)

OR

Code:
Special Effect - Create special effect at Position of (Triggering unit) of type...
[B]Set Effect = (Last created Special Effect)[/B]
Special Effect - Destroy [B]Effect[/B]

The above variable settings are very much unnecessary. Maybe you should include those in your tutorial.

You should really consider to fix your tutorial in terms of neatness. Use real triggers instead of hand-typed ones. Fix appropriate code tags. Else this tutorial has nothing much special (quite a number of people will learn triggering efficiency on their own as they play along with triggers).
What do you mean by fix appropriate code tags?
 

AgentPaper

From the depths, I come.
Reaction score
107
I would remove all the leak-preventing code. This tutorial is supposed to be about making efficient triggers, not preventing memory leaks. With the custom script in there, you're most likely just going to confuse beginners who don't know what leaks are yet. (which is who this is aimed at, I assume)

That said, looks much better than before.
 

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
Check this heading


There's one block of code with a
Code:
 tag but no [/code*]

Another block of code enclosed by [code][code][/QUOTE]
Thanks; fixed :o
[QUOTE]I would remove all the leak-preventing code. This tutorial is supposed to be about making efficient triggers, not preventing memory leaks. With the custom script in there, you're most likely just going to confuse beginners who don't know what leaks are yet. (which is who this is aimed at, I assume)[/QUOTE]
I'll consider that; thanks :thup:
[QUOTE]That said, looks much better than before.[/QUOTE]
Thanks.
 

U are a noob

Mega Super Ultra Cool Member
Reaction score
152
This is:
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)
faster than:
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)
It is efficiency because it can refer to a variable rather than a event response.
But if it was:
Code:
Unit - Create 1 Footman at somewhere...
Set Dummy = (Last created unit)
Unit - Add 10 expiration timer to Dummy
that is slower than:
Code:
Unit - Create 1 Footman at somewhere...
Unit - Add 10 expiration timer to (Last created unit)

Because there is only one use of (Last created unit) and setting it to a variable would be slower. Less lines is not always more efficient.
This is
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)
probably less efficient than:
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)
because it doesn't have to a do loop.
 

Knight7770

Hippopotomonstrosesquiped aliophobia
Reaction score
187
OMG. Wow. Do you even know what efficiency is?
This is:
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)
faster than:
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)
It is efficiency because it can refer to a variable rather than a event response.
But if it was:
Code:
Unit - Create 1 Footman at somewhere...
Set Dummy = (Last created unit)
Unit - Add 10 expiration timer to Dummy
that is slower than:
Code:
Unit - Create 1 Footman at somewhere...
Unit - Add 10 expiration timer to (Last created unit)

Because there is only one use of (Last created unit) and setting it to a variable would be slower. I suggest you give up on this tutorial until you actually know what you are talking about. Less lines is not always more efficient.
This is
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)
probably less efficient than:
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)
because it doesn't have to a do loop.
Well, you don't have to be so blatantly rude about it. Why don't you go ahead and write your own tutorial if you think mine is so horrible?
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Enough.

Civility, gentlemen, civility.

This tutorial may have some value, even if if it's not the most efficient configuration possible in every situation.
 

Oninuva

You can change this now in User CP.
Reaction score
221
Well, you don't have to be so blatantly rude about it. Why don't you go ahead and write your own tutorial if you think mine is so horrible?

He is trying to help. Why not take his advice instead of just thinking he is rude? Also he has written tutorials before in the past, so I do not know of what you refer to in this statement "Why don't you go ahead and write your own tutorial". :confused:
 

vypur85

Hibernate
Reaction score
803
In a lay person point of view, I would say;
This is:
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)
faster than:
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)
It is efficiency because it can refer to a variable rather than a event response.

Disagree. The latter is faster because it has one less variable and one less line.


This is
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)
probably less efficient than:
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)
because it doesn't have to a do loop.

The latter is tedious and unnecessarily lengthy. A loop will be easier to handle with.



Anyway, Knight, as I've mentioned, you should really consider using real trigger scripts to write the tutorial.
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)

=.=" Direct copy and paste~~
 

Zedzy

ℑΣÐℑΨ
Reaction score
41
Which is more efficient this:

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)

this:

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)

or 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)
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
2nd.

Instead of calling 7 BJs which already loop, you simply call one and it will loop through with that one execution. I mean, take advantage of the fluffy BJs while you can. :p (by fluffy, I mean it in a bad way not a good way ;))
 

U are a noob

Mega Super Ultra Cool Member
Reaction score
152
Well, you don't have to be so blatantly rude about it. Why don't you go ahead and write your own tutorial if you think mine is so horrible?
Well, yes. I was rude. I'm sorry about that. But I highly suggest you learn a little more before you write a tutorial. Efficiency is a lot more than just lines and to fully understand it you will need JASS knowledge. But seriously if people actually read your tutorial it might make people go backwards rather than forward.

In a lay person point of view, I would say;

Disagree. The latter is faster because it has one less variable and one less line.
Well we can't look at efficiency in layman's terms can we?

The latter is tedious and unnecessarily lengthy. A loop will be easier to handle with.
This thread is about efficiency not length.
 

AgentPaper

From the depths, I come.
Reaction score
107
I think, if you're going to talk about efficiency, you should include efficiency with how you make the triggers as well. Sure, having an action pasted 10 times might be faster than a loop from 1 to 10 doing the same thing, but the loops is far easier to modify later if you find an error, or you want to add something.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top