elmstfreddie
The Finglonger
- Reaction score
- 203
I'm SURE there's other tutorials on this... But I'm bored and I wanna write a tutorial
Note: This tutorial may be basic to some of you, but I think it could still be useful for many
Step 1: Unit Groups
I'm sure a lot of you use the action
This function is fine, but if underneath it you put something like Create 1 unit, it causes massive lag. If you are just using a unit group to count how many units there are, you should use something like the following instead.
It uses the same idea of picking every unit, but it only counts once, then makes that many amount of units instead of making a unit when it counts one in the group.
Step 2: Shortening If/Then/Else
The title may be misleading, but what I mean is when you have many If/Then/Elses, like under Then you have another If/Then/Else, then you have another... Until your trigger becomes massive.
Ability If/Then/Elses
Probably the most common If/Then/Else is with triggered spells, something like this:
Now, yes, this works, but is very ugly and long. This can be simplified EASILY. You just use:
Most of you probably know that, but some of you still probably do this for varying numbers that aren't simply the ability level. This is what I mean:
This can be simplified with math like so:
So instead of having many if/then/elses, this just creates 100*level of the ability footmen. Obviously you shouldn't be making this many units in a spell, so it is more likely you would use it with a range. For instance, you could say:
As I said in step 1, you should not be using unit groups. I only used one as an example. (300.00 + (50.00 x (Real((Level of Acid Bomb for (Triggering unit))))) pretty much means if it's level one, units within 350. Level 2, units within 400. Level 3, units within 450. And so on and so on for more levels.
String If/Then/Elses
Another way you may have really long If/Then/Else triggers is if you check units in regions, by doing something like If a unit is in this region, then do whatever. If it's not, then check if it's in this OTHER region. This can be WAY too long if you have a LOT of regions. The best thing to do, is have a region variable with an array of the amount of regions in your map. We will refer to this variable as MapRegions. The best way to simplify this: Integer loops. If you don't know what integer loops are, you could read my tutorial, but you shouldn't have to understand them to understand this trigger.
Note: You will need a seperate trigger that sets the MapRegion variable's arrays to the map's regions. This is the only con when using this shortening trick.
That's all you would need, instead of a long trigger of If/Then/Elses.
Another reason people may have long If/Then/Elses is if they are checking entered chat strings. For example, a colour changing trigger:
As you can see it's very long and time wasting, and there's a way to shorten this using loops and variables again. First, make a string variable. We'll refer to it has String. Give it an array of 12, the number of colours (and possibly 13 if you want to include black). We'll also need a Player Colour variable, also with an array of 13. Have a trigger on map initialization setting the variables to the different colours like so:
This may appear long, but this will extremely shorten your colour changing trigger, and also you can now use these variables on a different trigger.
Ok, so now lets fix your massive amount of If/Then/Elses into 1 loop. Lets use Integer B this time.
Note: There is no difference between Integer A and B.
As you can see, the trigger is a LOT shorter. I used If/Then/Else once (it's using if/then/else multiple functions so that it's easier for you to see, you can use the normal if/then/else) and a loop once, shortening the trigger dramatically. Now, when a player types -red all the way to -black, their units and colour will change to that. The same shortening technique can be utilized for taking over a player, except you use a player variable, and not a string variable.
Any other long triggers ya got? Post em here.
Other Links:
Integer A B - This in an integer tutorial, explaining some other ways you can use the looping features, and explaining the loop feature.
Note: This tutorial may be basic to some of you, but I think it could still be useful for many
Step 1: Unit Groups
I'm sure a lot of you use the action
Code:
Unit Group - Pick every unit in (<<a place>>) and do (Actions)
Loop - Actions
Code:
Unit - Create (Number of units in (<<a place>>)) Footman for Player 1 (Red) at (<<spawning place>>) facing Default building facing degrees
Step 2: Shortening If/Then/Else
The title may be misleading, but what I mean is when you have many If/Then/Elses, like under Then you have another If/Then/Else, then you have another... Until your trigger becomes massive.
Ability If/Then/Elses
Probably the most common If/Then/Else is with triggered spells, something like this:
Code:
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 1
Then - Actions
Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Unit - Set level of Animate Dead for (Last created unit) to 1
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 2
Then - Actions
Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Unit - Set level of Animate Dead for (Last created unit) to 2
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 3
Then - Actions
Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Unit - Set level of Animate Dead for (Last created unit) to 3
Else - Actions
Code:
Actions
Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Unit - Set level of Animate Dead for (Last created unit) to (Level of Acid Bomb for (Triggering unit))
Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 1
Then - Actions
Unit - Create 100 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 2
Then - Actions
Unit - Create 200 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Acid Bomb for (Triggering unit)) Equal to 3
Then - Actions
Unit - Create 300 Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Else - Actions
Code:
Unit - Create (100 x (Level of Acid Bomb for (Triggering unit))) Footman for (Owner of (Triggering unit)) at (Center of (Playable map area)) facing Default building facing degrees
Code:
Unit Group - Pick every unit in (Units within (300.00 + (50.00 x (Real((Level of Acid Bomb for (Triggering unit)))))) of (Center of (Playable map area))) and do (Actions)
String If/Then/Elses
Another way you may have really long If/Then/Else triggers is if you check units in regions, by doing something like If a unit is in this region, then do whatever. If it's not, then check if it's in this OTHER region. This can be WAY too long if you have a LOT of regions. The best thing to do, is have a region variable with an array of the amount of regions in your map. We will refer to this variable as MapRegions. The best way to simplify this: Integer loops. If you don't know what integer loops are, you could read my tutorial, but you shouldn't have to understand them to understand this trigger.
Note: You will need a seperate trigger that sets the MapRegion variable's arrays to the map's regions. This is the only con when using this shortening trick.
Code:
For each (Integer A) from 1 to <<set this to the amount of regions in your map>>, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(MapRegions[(Integer A)] contains (<<your unit>>) Equal to True
Then - Actions
<<your actions here>>
Else - Actions
Another reason people may have long If/Then/Elses is if they are checking entered chat strings. For example, a colour changing trigger:
Code:
Events
Player - Player 1 (Red) types a chat message containing - as A substring
Player - Player 2 (Blue) types a chat message containing - as A substring
Player - Player 3 (Teal) types a chat message containing - as A substring
Player - Player 4 (Purple) types a chat message containing - as A substring
Player - Player 5 (Yellow) types a chat message containing - as A substring
Player - Player 6 (Orange) types a chat message containing - as A substring
Player - Player 7 (Green) types a chat message containing - as A substring
Player - Player 8 (Pink) types a chat message containing - as A substring
Player - Player 9 (Gray) types a chat message containing - as A substring
Player - Player 10 (Light Blue) types a chat message containing - as A substring
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -Red
Then - Actions
Player - Change color of (Triggering player) to Red, Changing color of existing units
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -Blue
Then - Actions
Player - Change color of (Triggering player) to Blue, Changing color of existing units
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to -Teal
Then - Actions
Player - Change color of (Triggering player) to Teal, Changing color of existing units
Else - Actions
Code:
Events
Map initialization
Conditions
Actions
Set String[1] = -red
Set String[2] = -blue
Set String[3] = -teal
Set String[4] = -purple
Set String[5] = -yellow
Set String[6] = -orange
Set String[7] = -green
Set String[8] = -pink
Set String[9] = -grey
Set String[10] = -light blue
Set String[11] = -dark green
Set String[12] = -brown
Set String[13] = -black
Set PlayerColours[1] = Red
Set PlayerColours[2] = Blue
Set PlayerColours[3] = Teal
Set PlayerColours[4] = Purple
Set PlayerColours[5] = Yellow
Set PlayerColours[6] = Orange
Set PlayerColours[7] = Green
Set PlayerColours[8] = Pink
Set PlayerColours[9] = Gray
Set PlayerColours[10] = Light Blue
Set PlayerColours[11] = Dark Green
Set PlayerColours[12] = Brown
Set PlayerColours[13] = Black
Ok, so now lets fix your massive amount of If/Then/Elses into 1 loop. Lets use Integer B this time.
Code:
Events
Player - Player 1 (Red) types a chat message containing - as A substring
Player - Player 2 (Blue) types a chat message containing - as A substring
Player - Player 3 (Teal) types a chat message containing - as A substring
Player - Player 4 (Purple) types a chat message containing - as A substring
Player - Player 5 (Yellow) types a chat message containing - as A substring
Player - Player 6 (Orange) types a chat message containing - as A substring
Player - Player 7 (Green) types a chat message containing - as A substring
Player - Player 8 (Pink) types a chat message containing - as A substring
Player - Player 9 (Gray) types a chat message containing - as A substring
Player - Player 10 (Light Blue) types a chat message containing - as A substring
Conditions
Actions
For each (Integer B) from 1 to 13, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Entered chat string) Equal to String[(Integer B)]
Then - Actions
Player - Change color of (Triggering player) to PlayerColours[(Integer B)], Changing color of existing units
Else - Actions
As you can see, the trigger is a LOT shorter. I used If/Then/Else once (it's using if/then/else multiple functions so that it's easier for you to see, you can use the normal if/then/else) and a loop once, shortening the trigger dramatically. Now, when a player types -red all the way to -black, their units and colour will change to that. The same shortening technique can be utilized for taking over a player, except you use a player variable, and not a string variable.
Any other long triggers ya got? Post em here.
Other Links:
Integer A B - This in an integer tutorial, explaining some other ways you can use the looping features, and explaining the loop feature.