- Joined
- Mar 14, 2009
- Messages
- 98
I was recently told that triggers with two events are evil. The person seemed like a trustworthy source, but I didn't want to hijack the thread, so I'm asking here. Why are triggers with two events evil?
Almost every trigger has multiple events.
A unit starts the effect of an ability
That's 16 events, right there.
I don't think he fully understands the nature of events. I don't have a full grasp either but I am confident it works something similiar to this, but hopefully faster/smoother/smarter/etc.
You want 5 units to trigger the same event = IEicking heros from different buildings
You either
A) Attach those specific units to a single trigger and register it in the event manager.
The event manager's listener picks up an event, then checks the even type against its registered events. It then finds the event that matches the event type, then checks the conditions for that event (If its one of those 5 buildings) and then runs the trigger.
B) Make seperate triggers for each unit, which requires the same thing as above, but just takes up more space. Either way it has to search through 1 to N units registered for the trigger type.
C) Make the trigger generic and then put some if-then checks to see if the unit type ids match up. So now the manager runs the trigger on every single hit, which I do believe means a function call every single time, followed by boolean checks and not the other way around.
Of course this is all speculation.
On a side note, your friend could mean multiple event TYPES. Whereas you mix a unit gets attacked and a unit is trained event. When one event triggers the code it leaves the coder having to watch for potential null references, which is solved by some error-checking.
IE: If your unit is attacked event shoots off, and you are trying to reference the event's trained unit you are going to get a null reference, which is potential for problems.
i like making generic events with alot of If Then Else (multiple function) in there its more understandable and takes up less time and space then making a seperate trigger for every If The Else