HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

More effecient triggering

03-20-2005, 01:21 AM#1
johnfn
I'm just going to go through a few of the biggest things in triggering that will literally save you hours of time when you trigger.


I'll update this whenever I have time/feel like it :P

The Structure

"The structure," you say, "It sounds like a building!" Well, unfortunately, it has nothing to do with a construction. However it is an incredibly helpful triggering tool that not very many people know about. In the most basic terms, its like several arrays of data, accessable by the array index. You'll get used to this from practice.

Why would I want one?

Well, lets say you were making a TD. You wanted to have different units every level, but you also wanted to have a different amount of units every level. Without knowing anything about a structure, you might write something like this

Trigger:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Equal to 1
Collapse Then - Actions
Unit - Create 15 Footman for Player 9 (Gray) at (SpawnRegion) facing Default building facing degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Equal to 2
Collapse Then - Actions
Unit - Create 20 Priest for Player 9 (Gray) at (SpawnRegion) facing Default building facing degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Level Equal to 3
Collapse Then - Actions
Unit - Create 50000 Rifleman for Player 9 (Gray) at (SpawnRegion) facing Default building facing degrees //ouch
Collapse Else - Actions
//and so on
Looks terrible, doesnt it?


Well, you should realize the need for a structure when you see a lot of repeating code like this. Thats the first and most obvious sign that you need one.

So how do I go about making one of these?

Well, first you need to make two arrays. They will be an array of unit types (the unit type in the TD) and an array of integers (the amount of units). Why are you doing this? Well, a structure is when you combine two or more related data types into one. So I am going to have the integers correspond to the unit-types, so that instead of a lot of if statements, I can just use the index to get the stats of whatever level I like.


This will naturally come at the beginning of the map. So lets see where this will take us:

Trigger:
Collapse Init
Collapse Events
Time - Elapsed game time is 0.10 seconds
OR
Map initialization
Conditions
Collapse Actions
--------Footman Info--------
Set Units[1] = Footman
Set AmountOfUnits[1] = 15
--------Priest Info--------
Set Units[2] = Priest
Set AmountOfUnits[2] = 20
--------Rifleman Info--------
Set Units[3] = Rifleman
Set AmountOfUnits[3] = 50000 //still ouch

Destroy (This trigger) //effeciency

You should be starting to see where this is going, no?

Well, now what we are going to do access the structure with the index number of the level that the TD is. You will be suprised just how short the code got:

Trigger:
NewLevel
Collapse Events
Time - TmrNewLevel expires
Conditions
Collapse Actions
Set Level = Level + 1 //just for clarification
Unit - Create AmountOfUnits[Level] Units[Level] for Player 9 (Gray) at (SpawnRegion) facing Default building facing degrees



"But wait!" I say. "What if you want them to come out of a different region each time?". Surely you now know where I am going with this. Time to add another variable to the structure, and you should be able to guess at this code (if not, then reread the tutorial)

Trigger:
Init
Collapse Events
Time - Elapsed game time is 0.10 seconds
Conditions
Collapse Actions
--------Footman Info--------
Set Units[1] = Footman
Set AmountOfUnits[1] = 15
Set SpawnRegion[1] = (SpawnRegion1)
--------Priest Info--------
Set Units[2] = Priest
Set AmountOfUnits[2] = 20
Set SpawnRegion[2] = (SpawnRegion2)
--------Rifleman Info--------
Set Units[3] = Rifleman
Set AmountOfUnits[3] = 500000 //...
Set SpawnRegion[3] = (SpawnRegion3)

And then the last piece:

Trigger:
NewLevel
Collapse Events
Time - TmrNewLevel expires
Conditions
Collapse Actions
Unit - Create AmountOfUnits[(Level)] Units[(Level)] for Player 9 (Gray) at (Center of SpawnRegion[Level]) facing Default building facing degrees


Alright, I hope that helps with your understanding of triggers and general, and saves you time when you have a lot of repititive triggers to write.
03-21-2005, 07:20 PM#2
Guest
Wow I'd give ya rep if I could but:
"You must spread some rep before giving it to johnfn again"
So until I can give ya rep I'll post :D
Ok wow this helps A LOT instead of having to do time elapsed...create unit...at region... it cuts it down A LOT ;) and please do update it if you have time (and if you don't mind get into the variables ^_^ ) But you don't have to. Anyways..
Thx for the tutorial johnfn~
~Piece
07-07-2005, 02:09 PM#3
MeTaCo
Well explained, and yes a lot of time saved, not only that but File size would definately be saved too, and less leaks!
12-30-2005, 05:58 AM#4
DD_Draco
Nice tutorial serves its purpose an well explained, as MeTaCo said is saves file size and will reduce leaks gj.
12-30-2005, 10:40 AM#5
AnarkiNet
good for beginners. i'd reccomend editing it with the new trigger tags though :)
01-15-2006, 09:05 PM#6
johnfn
Done!

It looks a lot better now :)
01-16-2006, 03:41 AM#7
Ignitedstar
Good job. It's nice to see something that will save time and space. :)
02-02-2006, 05:42 PM#8
MrApples
Why do you do stuff at Elapsed Game Time is 0.10 seconds, thats not efficent triggering. Using Map Initlization may increase your loading time by a quater second, but its worth it over the lag your going to get for doing starting triggers at 0.10.
02-02-2006, 06:09 PM#9
Captain Griffen
It would also be more efficient to destroy single time running triggers afterwards.
02-03-2006, 01:23 AM#10
johnfn
Quote:
Originally Posted by MrApples
Why do you do stuff at Elapsed Game Time is 0.10 seconds, thats not efficent triggering. Using Map Initlization may increase your loading time by a quater second, but its worth it over the lag your going to get for doing starting triggers at 0.10.

Yeah, me using 0.10 stems from me doing EVERYTHING in init (that includes initializing multiboards) Also, certain triggers have a tendency to screw up Map Init, so I just lean on the safe side. Also, I haven't noticed any lagging yet (although if I ever do, I'll certainly take your advice )


Quote:
It would also be more efficient to destroy single time running triggers afterwards.

That's a good idea, I'll put that in there.
08-16-2006, 07:54 AM#11
Waynebebay
Not only good for someone who wants to make a TD but great for a firm lesson in arrays.
09-02-2006, 08:06 AM#12
Tobbz
Quote:
(and if you don't mind get into the variables ^_^ )

Yes it would be nice if you did so Jonfn
Im not so good in mapmaking atleast not triggering =/
But it would be nice to get my started TD finished i only have the Levels left but..I cant get it to work.

anyway Good Tutorial.
01-22-2007, 04:25 PM#13
scythetleppo
efficient


not effecient
12-06-2008, 06:59 PM#14
LordChicken
wow looks good
07-20-2009, 05:20 PM#15
Scaly-D
I guess I'm the only one who feels this way, but this was very difficult for me to follow. Alone, it didn't offer any help - I had to learn about arrays elsewhere to even understand this. And still this seems incomplete to me. I'm not new to map-making, but this goes right over my head (well, kinda hits my forehead and slides past). You should either put more elaborate descriptions of each step or warn the reader that they need to be familiar with arrays at the beginning (then again, it seems to me that if I were familiar with them, I wouldn't need this tutorial).