HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Better coding style...

07-02-2004, 11:08 PM#1
ForgottenLight
I'm curious as to what the general opinion is. What is better, a smaller number of very large triggers, or a large number of small triggers? Which do you find better, easier, more eficient?
07-03-2004, 02:14 AM#2
th15
Ideally you should have 1 trigger for each event you use and then have a long if-then-else nest for each event. This minimises the amount of triggers the computer will have to check when an event happens.

Of course its also monstrously messy. Usually i'll make the biggest set of stuff one long trigger and have ancillary stuff on their own small triggers.
07-03-2004, 02:26 AM#3
weaaddar
Jass is your answer. Long If then else trees are for nubs.
The correct style for minimalism is one trigger for everything having all the events and detecting which event fires for maxium effeciency...

I'm kidding. Its up to you. I'm sticking with this style
Class_functionName for member functions
and m_VariableName for member variables.
Oh yeah I also stick to one trigger per event, and I like to make sure everything is handled and nothing is left to chance.
07-03-2004, 02:36 AM#4
linkmaster23
Personally I like big clean triggers. :) A lot of small ones become easier to read, but the big ones make your map seem much more professional.
07-03-2004, 03:59 AM#5
th15
More professional to whom? Your palyers don't see it and if you're mapping for anyone else besides the players than you've got some serius re-thinking to do.
07-03-2004, 05:35 AM#6
Ninja73
Well i always try 2 watch my kbs, and each time u create a new trigger it takes 1 kbs, however if u use a bigger trigger and put that triggers info onto it, it will sometimes b able 2 save u that extra kbs. This is good when u have a big map that u dont want 2 b huge in size.
07-03-2004, 05:32 PM#7
weaaddar
Some of us release APIs and enjoy open sourcing our work so others can understand it.
07-03-2004, 10:23 PM#8
Vexorian
Having a lot of triggers is like a lot of handles is like a lot of special effects, see?
07-03-2004, 10:27 PM#9
linkmaster23
Makes your map look pretty. :)
07-03-2004, 10:31 PM#10
Deathperception
I think if a big trigger can get the job done and it doesn't confuse you its ok :D .

Although JASS is the most efficient but I'm still learning it :\ .
07-04-2004, 09:58 PM#11
Vexorian
Quote:
Originally Posted by linkmaster23
Makes your map look pretty. :)
I have all my spells triggers merged into one trigger but it still uses separated functions because of my special events system, works nicely and doesn't confuse
07-05-2004, 03:18 PM#12
Cubasis
Oh, and ... Many triggers are ok, as long as they're doing different stuff. If you have 12 triggers doing the same stuff for the same player, in 90% of the time, you can combine it to a single pretty trigger.

~Cubasis
08-01-2004, 01:35 PM#13
Grater
I like to do the optimal thing, for example in a TD I'm making, with 56 waypoints, I use precisely 3 triggers for waypoint redirection. In the average it'd it'd be 56 triggers - 1 for each waypoint region. I use 1 trigger to add the waypoints to an array, a second to add the events to the third trigger, that checks if the unit is in the right waypoint and if so redirects it.

Arrays, Loops and creating triggers/events on the fly are very good ways to make compact and effecient triggers. Ultimately I always aim for the programming principle of elegance - generally avoiding any brute force approach like copy-pasting a trigger for each player/waypoint/whatever...
08-01-2004, 03:48 PM#14
th15
I disagree that loops improve efficiency. They make code neater and much shorter by eliminating the need to re-iterate triggers.

However, if not used properly, non-smart loops or badly written loops I think are the major cause of CPU cycle wastage.

I would say that there are two dimensions to decide the efficiency of a trigger: CPU time required and length of code. Longer code equates longer loading time, potential for human error and a slightly larger file size. CPU time is how much processing power your triggers use. Quite simply, laying out all the intructions for the computer before hand would greatly reduce the amount of processing required, but greatly increase code length.

My approach to it is to minimize code length up to and until a point where compressing my code any further will push modern CPU's beyond their limit. This I see as the only logical, effective approach. That's not to say that I always acheive that level of efficiency though :)
08-01-2004, 07:10 PM#15
Xinlitik
I'm in agreement with th15. In the case of waypoints, it seems much more efficient to have one small function that runs per waypoint rather than a large loop ( I assume you looped through all the possibile rects until you found the one that the unit was in ) that runs for all of them. A waypoint trigger is run frequently, so it would be nasty to have a huge loop in it.