DialogUsed Event needs special treatment. if you dont disable the button at the start of execution you can queue the button pressed event resulting in more than one executions.
One exception is the mouse moved event. It should be used only in combination with a certain player (not any player). Have a look in my signature and check the map "banshee fight" if you want to know more.
Key pressed event shouldn't be used at all (not even on a per player basis) because it will lag in multiplayer games.
Instead of ANY X (i.e. any unit being killed) you should use dynamic Event adding with one specific unit; anyway there is another "trick": use a variable in the event, but be carefully with i.e "no unit".
Conditions:
Take care what conditions you are using. There are several which costs alot of performance (pathing costs between 2 points, etc).
Having the same conditions again and again, you should consider making a custom function which checks the conditions and returns a boolean.
Actions & Functions:
functions should be used to calculate things and return the result. for example i am using functions to return the index of an array which is basically "search within a list".
functions always have to return something (and galaxy checks if every branch of your code will do so), do that at the very end of that function with a variable you have set during the functions execution.
When you combine functions with generic events (this is typically for libraries that you'll distribute to others) you can use them to return (typically from a variable) info about the triggering items and causes.
Never use Pick Each Integer / Pick whatever inside a function or action
Variables:
Use constants for constant values (capt obvious), i.e Number of max players
Use records whenever you have to group variables, for example:
instead of using a variable heroes[player], use a record
players[player].hero, you will most likely group more variables for the players.
put your variables (in the folder) where they are used, if used at several places, put them where they are initialized
custom values on units : alway make a index list of the custom values and what they mean (i.e. 1 = Status, 2 = reached target, 3 = X-coordinate , etc)
Dialogs:
Only create dialogs on a per player basis unless you need to resize the whole dialog (not the dialog item), because that's not possible on a per player basis.
Create a custom action/function to create dialog items like pulldown. etc (you always have to set height,width, anchor)
Special stuff:
Global attack is implement best with triggers, there is no data solution that performs well. In my map TRD, i need all zombies to attack the heroes from any place of the map. In wc3 it was possible to set aquisition range to 500 and just give full vision to enemy to achieve that. Doing that in sc2 will not perform well. Also all other options i have tried didnt perform well, only a periodic action that checks direct distance is able to perform okish. (check trd map in my signature)
Nice list, here's a couple things you might want to mention when you edit this later
Events:
You should dynamically create your dialog events and any events that you use conditions for (I.E. you have a trigger with a condition checking for a boss being damaged which uses any unit and a condition to check that it's the boss unit, could instead be dynamically generated with that boss as the triggering unit.)
Actions:
Actions should be used for two purposes: 1) to help organize your code (You have a 100 lines that could be consolidated and labeled in an action, similar to comments) and keep it from cluttering up triggers, 2) You said this already, but when you are repetitively coding the same thing.
Functions:
When you combine functions with generic events (this is typically for libraries that you'll distribute to others) you can use them to return (typically from a variable) info about the triggering items and causes.
Variables:
Records are also a great way of creating multiple iterations of the same variables
I.E.
Not the best example but a rough idea of what I mean.
Not sure what category:
Another thing that you might want to note, is that you shouldn't create the same Dialogs and dialog items on a player basis, instead you should create one set and adjust it per player.
So, I'm a very sloppy triggerer and I'm looking to cleanup triggers on some of my maps. I have some questions - I'm sure they all sound dumb, not great at triggers.
First, is there any good tutorial for creating your own actions/functions/etc? I have no experience with these and am not exactly sure how to use them or what they are best used for.
Quote:
If there is no event, dont use a trigger, use an action...
What is the reason behind this? Are triggers somehow inherently less efficient than making your own action? Or is it just better organization?
Quote:
In general events should be used as less as possible to maintain clear code and good performance.
I don't get this - aren't events necessary to make your trigger run? How do you eliminate them? What are some common examples of excessive/redundant event usage?
Quote:
One thing i see again and again is the use of the MapInit event more than once. There should be only ONE entry point to your map.
Why is this? The only reason I ever do it is if I need something with a wait in it to run at the start of the map (so I want other things to be not waiting on the wait) but I'm not sure why its better to have it under a time elapsed 0.001 rather than multiple MapInit. Maybe its because I don't really get what MapInit is doing, I always just think of it as the same thing as time elapsed 0.001 except without that tiny bit of delay.
Quote:
Avoid the use of periodic events, they cost too much performance, instead call an custom action (instead of turning your former trigger on) :
I REALLY don't understand this one. Why do periodic events cause more lag than doing it this way? Plus I don't get how your workarounds work; the While loop will stop at one failure to meet conditions but for many periodic event triggers you want them to continue to keep going even if they do fail a condition check once.
Quote:
Instead of ANY X (i.e. any unit being killed) you should use dynamic Event adding with one specific unit; anyway there is another "trick": use a variable in the event, but be carefully with i.e "no unit"
Lost me again, not sure how to do Dynamic Events (Do you mean using custom script to add events?) but also I'm not sure what you mean by the other "trick" you can use. Also, I'm presuming this is only applicable if you are using "any x" when you actually want it to be a specific unit, just one not on the map yet. Because I don't see how its any better to add hundreds of events to one trigger dynamically, especially when you said to avoid using events earlier.
Quote:
Take care what conditions you are using. There are several which costs alot of performance (pathing costs between 2 points, etc).
Wondering if you could be more specific and say what other conditions cost a lot of performance besides pathing costs between 2 points?
If there is no event, dont use a trigger, use an action...
What is the reason behind this? Are triggers somehow inherently less efficient than making your own action? Or is it just better organization?
each trigger creates a variable and a function just for being a trigger (in galaxy), so it takes away space, but more important than that is the better organization, having only triggers with events shows you right away where to go in your code and what will run (assumming it's bigger than 1 week work)
In general events should be used as less as possible to maintain clear code and good performance.
I don't get this - aren't events necessary to make your trigger run? How do you eliminate them? What are some common examples of excessive/redundant event usage?
2 things here, group your events, meaninig instead of using X triggers with unit dies event, use one trigger with that event and use a Switch or If THen Else to check every case. 2nd thing is, think about it first, do you really NEED an event and do you really NEED this one, or isnt there a more specific event that you could use.
One thing i see again and again is the use of the MapInit event more than once. There should be only ONE entry point to your map.
Why is this? The only reason I ever do it is if I need something with a wait in it to run at the start of the map (so I want other things to be not waiting on the wait) but I'm not sure why its better to have it under a time elapsed 0.001 rather than multiple MapInit. Maybe its because I don't really get what MapInit is doing, I always just think of it as the same thing as time elapsed 0.001 except without that tiny bit of delay. Quote:
Do ONE trigger with MapInit, then call actions in this trigger which must be executed on map start, add a wait and call the actions that must be called later. if you ever leave the map and come back half a year later, you wont have to check/find all triggers with mapInit event to see whats going on on mapstart
Avoid the use of periodic events, they cost too much performance, instead call an custom action (instead of turning your former trigger on) :
I REALLY don't understand this one. Why do periodic events cause more lag than doing it this way? Plus I don't get how your workarounds work; the While loop will stop at one failure to meet conditions but for many periodic event triggers you want them to continue to keep going even if they do fail a condition check once. Quote:
periodic events really behave with low performance, a while loop is way more effient. the conditions for the while loop are ther ones that would have turned off your former periodic trigger and you call the loop action when turninig your former trigger on. it's not a replacement for the content of the trigger (which might contain conditions that are allowed to fail)
Instead of ANY X (i.e. any unit being killed) you should use dynamic Event adding with one specific unit; anyway there is another "trick": use a variable in the event, but be carefully with i.e "no unit"
Lost me again, not sure how to do Dynamic Events (Do you mean using custom script to add events?) but also I'm not sure what you mean by the other "trick" you can use. Also, I'm presuming this is only applicable if you are using "any x" when you actually want it to be a specific unit, just one not on the map yet. Because I don't see how its any better to add hundreds of events to one trigger dynamically, especially when you said to avoid using events earlier.
yes, i mean that. the other trick is to use instead of any unit a unit variable and set it during the game. this allows dynamic event units too and doesnt require custom script.
Take care what conditions you are using. There are several which costs alot of performance (pathing costs between 2 points, etc).
Wondering if you could be more specific and say what other conditions cost a lot of performance besides pathing costs between 2 points?
anything that has to calculate something, or go through a list of things. having lots of units on the map, you might think about unit groups. use a local variable to calculate the unit group once, instead of calling the action (unit group in region with cond i.e.) again and again.
periodic events really behave with low performance, a while loop is way more effient. the conditions for the while loop are ther ones that would have turned off your former periodic trigger and you call the loop action when turninig your former trigger on. it's not a replacement for the content of the trigger (which might contain conditions that are allowed to fail)
So basically if I didn't want any conditions I could just use Repeat Forever instead of While and it would still be more efficient then periodic effect? The idea is just that loops in general are more efficient?
Quote:
Do ONE trigger with MapInit, then call actions in this trigger which must be executed on map start, add a wait and call the actions that must be called later. if you ever leave the map and come back half a year later, you wont have to check/find all triggers with mapInit event to see whats going on on mapstar
Yea, I was just trying to figure out if this was an organization thing or it had some impact on performance or something to have more than one mapInit.
Quote:
the other trick is to use instead of any unit a unit variable and set it during the game. this allows dynamic event units too and doesnt require custom script.
Oh, I thought you couldn't use variables in events for some reason. Or is that only specific kinds of events?
You can only use initialized variables on events dyniamically. that is, an action or whatever registers a new event for an exisitng trigger while the map is already running
Here another list by Funky. List will be updated. The following is a personal opinion:
General:
Events:
Conditions:
Actions & Functions:
Variables:
instead of using a variable heroes[player], use a record
players[player].hero, you will most likely group more variables for the players.
Dialogs:
Special stuff:
Nice list, here's a couple things you might want to mention when you edit this later
Events:
You should dynamically create your dialog events and any events that you use conditions for (I.E. you have a trigger with a condition checking for a boss being damaged which uses any unit and a condition to check that it's the boss unit, could instead be dynamically generated with that boss as the triggering unit.)
Actions:
Actions should be used for two purposes: 1) to help organize your code (You have a 100 lines that could be consolidated and labeled in an action, similar to comments) and keep it from cluttering up triggers, 2) You said this already, but when you are repetitively coding the same thing.
Functions:
When you combine functions with generic events (this is typically for libraries that you'll distribute to others) you can use them to return (typically from a variable) info about the triggering items and causes.
Variables:
Records are also a great way of creating multiple iterations of the same variables I.E.
Not the best example but a rough idea of what I mean.
Not sure what category:
Another thing that you might want to note, is that you shouldn't create the same Dialogs and dialog items on a player basis, instead you should create one set and adjust it per player.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
@FunkyUserName: Go
Very good list
I would highly suggest for any aspiring coder to read Robert Martin's "Clean Code" It covers the entire list above and more.
So, I'm a very sloppy triggerer and I'm looking to cleanup triggers on some of my maps. I have some questions - I'm sure they all sound dumb, not great at triggers.
First, is there any good tutorial for creating your own actions/functions/etc? I have no experience with these and am not exactly sure how to use them or what they are best used for.
What is the reason behind this? Are triggers somehow inherently less efficient than making your own action? Or is it just better organization?
I don't get this - aren't events necessary to make your trigger run? How do you eliminate them? What are some common examples of excessive/redundant event usage?
Why is this? The only reason I ever do it is if I need something with a wait in it to run at the start of the map (so I want other things to be not waiting on the wait) but I'm not sure why its better to have it under a time elapsed 0.001 rather than multiple MapInit. Maybe its because I don't really get what MapInit is doing, I always just think of it as the same thing as time elapsed 0.001 except without that tiny bit of delay.
I REALLY don't understand this one. Why do periodic events cause more lag than doing it this way? Plus I don't get how your workarounds work; the While loop will stop at one failure to meet conditions but for many periodic event triggers you want them to continue to keep going even if they do fail a condition check once.
Lost me again, not sure how to do Dynamic Events (Do you mean using custom script to add events?) but also I'm not sure what you mean by the other "trick" you can use. Also, I'm presuming this is only applicable if you are using "any x" when you actually want it to be a specific unit, just one not on the map yet. Because I don't see how its any better to add hundreds of events to one trigger dynamically, especially when you said to avoid using events earlier.
Wondering if you could be more specific and say what other conditions cost a lot of performance besides pathing costs between 2 points?
Thanks!
each trigger creates a variable and a function just for being a trigger (in galaxy), so it takes away space, but more important than that is the better organization, having only triggers with events shows you right away where to go in your code and what will run (assumming it's bigger than 1 week work)
2 things here, group your events, meaninig instead of using X triggers with unit dies event, use one trigger with that event and use a Switch or If THen Else to check every case. 2nd thing is, think about it first, do you really NEED an event and do you really NEED this one, or isnt there a more specific event that you could use.
Do ONE trigger with MapInit, then call actions in this trigger which must be executed on map start, add a wait and call the actions that must be called later. if you ever leave the map and come back half a year later, you wont have to check/find all triggers with mapInit event to see whats going on on mapstart
periodic events really behave with low performance, a while loop is way more effient. the conditions for the while loop are ther ones that would have turned off your former periodic trigger and you call the loop action when turninig your former trigger on. it's not a replacement for the content of the trigger (which might contain conditions that are allowed to fail)
yes, i mean that. the other trick is to use instead of any unit a unit variable and set it during the game. this allows dynamic event units too and doesnt require custom script.
anything that has to calculate something, or go through a list of things. having lots of units on the map, you might think about unit groups. use a local variable to calculate the unit group once, instead of calling the action (unit group in region with cond i.e.) again and again.
So basically if I didn't want any conditions I could just use Repeat Forever instead of While and it would still be more efficient then periodic effect? The idea is just that loops in general are more efficient?
Yea, I was just trying to figure out if this was an organization thing or it had some impact on performance or something to have more than one mapInit.
Oh, I thought you couldn't use variables in events for some reason. Or is that only specific kinds of events?
You can only use initialized variables on events dyniamically. that is, an action or whatever registers a new event for an exisitng trigger while the map is already running
Go play Antioch Chronicles Remastered!
Also, coming soon, Antioch Episode 3: Thoughts in Chaos!
Dont like mapster's ugly white? Try Mapster's Classic Skin!
@TheSkunk2: Go I never got beyond basic triggering, but I remembered this being way over my head!! You might find it accessible now
http://www.sc2mapster.com/forums/resources/tutorials/2532-video-triggers-basic-functions-action-condition-definitions/#p1