• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Solved] Question about multiple instances of triggers with same event

Level 6
Joined
Jan 9, 2024
Messages
30
Hello, if i have many events, for example:
Unit - cast spell
(condition a then)
(actions bla bla)

(condition b then)
(actions bla bla)


it's better to make just one trigger with many conditions for every different action?
Or its better to spread them as single triggers for evey unique action, like:
Unit - cast spell
(conditions - Spell a)
(actions bla bla)
-------------------------
Unit - cast spell
(conditions - Spell b)
(actions bla bla)

Which way is better?
 
Better is a single trigger. Except when you create a local trigger for a specific unit for a certain period of time.
It's also best to never use Conditions and instead check conditions in Actions using if/then/else.
Every Conditions check like "Used skill is Blizzard" creates an extra function, but if you do everything in Actions, that won't happen.

If you're thinking about it, why not just switch to Jass? Thoughts about how to make things "better" or "more optimized" indicate that you may be ready for this step.

But okay, let's think about GUI a little.
Yes, when a single GUI trigger has many actions, it can lag and become less visually appealing, but you can still split actions into multiple triggers.
With YDWE PK, you can use "call" and "ExecuteFucntion" to create and use your own functions.
With the default GUI, you can run another trigger.
It might look like this: If (condition) then (run trigger)
This way, you can have one trigger for each event, which will, if necessary, trigger other triggers that don't have events.
This is a kind of sorting.
Is this better than multiple triggers with the same event? Yes, this way you know exactly the order in which actions will be executed.
Is it more optimized? A little, because the event will only proc once.

The problem is that every GUI trigger, even if empty, the following happens:
Always created:
  • A function that runs when the map is initialized. (Btw, if you have a lot of triggers, this can lead to an "operation limit" which will break most of your triggers)
  • A function for "Actions"
  • Global trigger variable
  • New trigger
If events is used:
  • New event for trigger
If conditions used:
  • A function for conditions

If you understood everything listed above, then you've already guessed that GUI triggers suck in terms of optimization anyway.
I could fix this in YDWE PK, but I don't want to mess around with C++ for the sake of a couple of smart people.

To summarize: Don't use Conditions and try separating triggers using "Run Trigger" - it will definitely be better.
But when it comes to triggers for custom abilities, the best optimization option is to store the functions in a hashtable and then call them in the "unit uses ability" event.
We save the function by the parent key, which is the Id of a specific ability, and then when casting, we check if the Id of the applied ability is written to the hashtable, we run the function of this ability.
How do you do this with the default GUI? Idk, you don't even have all the functions for working with a hashtable.
 
Thank You a lot for this knowledge, i understood nearly all (reading slowly).
Your answer makes no space for additional questions + many rethinks, so big Thanks prob all i can say, i wish i could rep+.
Not sure JASS will be my future, GUI have advantage of showing possible functions (so i dont have to remember/seek for)
Only chance for switch is need to click some paremeters 10 times to change one digit will push my inpatience over limits.
(i'll try optimise, tho im not in this level yet)

P.S. i was reading about this YDWE chinesse editor like year ago,GJ some sort of legend story. (once or never used it but i bet its downloaded)
A lot of it comes down to maintainability. You want to avoid spaghetti code as it can be very difficult and error prone to make changes.
I understand, i separate catalogs with types of triggers, using lot of comments every section etc, naming global variables as clearly as possible.
But Tbh.. mostly bcs i prefer to make things linked and related on each other, it allows for global changes in gameplan just by little rework. Is risky when started bad as it ends like You described, but if handled well it starts to live on its own, like makes possible to rely new things on those already coded (GUI'ed?). Not sure its true spaggetti more like a tree (or i hope so).

P.S. i also remember reading Your answers like "max array size" and many more with specialistic knowledge.

Thank for advices whats a bit overwhelminmy needs and written by Members what mades me little ashamed.
 
Back
Top