• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Trigger Editor slow af

Status
Not open for further replies.
Level 11
Joined
Jan 25, 2017
Messages
213
It's because I'm working on a looooooooong trigger in GUI- it's not that complicated- and performs well(?) in-game, although I haven't tried multiple people at the same time.

Event- Unit starts effects of an ability. No waits or anything, just a ton of If/Then/Else statements to check items in hero's slots and does different effects based on certain combinations of items. So I don't think the problem is the trigger itself- it's the length- if I try and copy and paste anything in that trigger I'm waiting a fair few seconds before anything registers. If I open another blank trigger than it works pretty good.

So.... obviously I need to split up the triggers to have a better time in the editor. Will I have problems if I have multiple triggers with the same event/conditions? Will it be better (after making everything in sections) to copy all the If/Then/Else sections into just one trigger or will it be okay firing at the same time?
 
Level 11
Joined
Jun 2, 2004
Messages
849
The runtime difference would be trivial, so no you don't need to re-merge the trigger. Separate triggers means it checks every condition every time, whereas an if/else chain will stop as soon as it hits a positive. Assuming each possibility is equally likely, that's only a 50% reduction in overhead.

Long if/else chains can be a pain to maintain, so you might want to consider changing your logic sometime down the line. If it works it works and that's fine, of course. Depending on what you're doing though you might be able to simplify things using various tricks like enumeration.
 
Level 11
Joined
Jan 25, 2017
Messages
213
Thanks for the response! It was helpful. I should have described it better though, I actually have everything at once right now- i.e. my if/else aren't actually chained together. I should just post a clip of my trigger but I'm not on my desktop with my map right now so I'll make a fake one.

Event-
If: Conditions
Then: Actions, sometimes more If/thens
Else: (sometimes an action or two but usually blank)
///New If/Else statement///
If: different conditions
Then: different actions
Else:
...and repeat 30+ times

It's okay if multiple run in one go if all the conditions are met, which is why I never bothered chaining them.

I originally put a 'skip' action at the end of each 'then' statement so it wouldn't have to go through everything, but then I found it didn't make that much of a difference (right? or will I see it in multiplayer?)- and that way I can include a lot of the same stuff at the end, instead of tacking it on at the end of each individual 'Then' statement.
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
use "run trigger". It makes it a lot easier. You can then use in the then-statement: run trigger "A" and skip remaining actions. In the trigger "A" you can put, what you wanted to put at the end of the first trigger. You can also use run trigger to split a trigger "B" into two trigger "C" and "D". Just put at the end of C: run trigger D.
but then I found it didn't make that much of a difference (right? or will I see it in multiplayer?)
You probably won't notice it by itself, but it will cause problems together with other performance critical situations. I would definitely use the skip action, if you only want one thing to happen.
 
Level 11
Joined
Jan 25, 2017
Messages
213
Wouldn't "run trigger" cause some problems with MUI though? Why would it be more desirable than having the same condition?

I already have a fall back if there are undesired consequences from multiple things happening, so if all the conditions are right then having the then-statements run at the same time is perfectly fine. I thought I would need the skip action to prevent the trigger from going through all the other conditions and thus save time/lag- but it seems to happen fast enough anyway.

I guess my other separate, but sort of related, question is if it's better to have multiple triggers or all consolidated into one with If/then doing most of the conditions, or if the difference is minimal and it just boils down to manageability of the trigger editor.

EX:
Trigger 1= A footman dies
>...
Trigger 2= An Archer dies
>....

vs.

Trigger (all) = a unit dies
If unit equals footman Then >....
If unit equals archer Then >...
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
Wouldn't "run trigger" cause some problems with MUI though? Why would it be more desirable than having the same condition?
I can't see any problems with MUI with this method. It's better, because you do not have to call functions again like GetTriggerUnit(), but you can use a variable instead which is slightly faster.
It does not make much of a difference though, so do what you prefer.
EX:
Trigger 1= A footman dies
>...
Trigger 2= An Archer dies
>....

vs.

Trigger (all) = a unit dies
If unit equals footman Then >....
If unit equals archer Then >...
Same here. If you store GetTriggerUnit() to a variable in the second one, you only have to call GetTriggerUnit() once. In the first example you have to call once per trigger. So the second one is slightly faster. Another advantage is, that once a condition was met (unit is footman), you can skip the other conditions, so it's 2 times as fast in average.
As all of these conditions are probably not performance critical, unless they have to run very often, you can do what you prefer.

You can do the same for spells:
A unit casts an ability

if ability=... spell1
if ability=... spell2

But usually it's better to use seperate triggers, as it makes it more readable. If the actions are similar I would put them in one trigger.
 
Level 11
Joined
Jan 25, 2017
Messages
213
Thanks, this really helps my understanding of triggers a lot.

I can't see any problems with MUI with this method. It's better, because you do not have to call functions again like GetTriggerUnit(), but you can use a variable instead which is slightly faster.
Oooh, I didn't even realize that you wouldn't need to reset the variable like Triggering Unit if you ran the trigger ignoring conditions.

Another advantage is, that once a condition was met (unit is footman), you can skip the other conditions, so it's 2 times as fast in average.
Oh, so the skip condition DOES make it more efficient.

Thanks Jampion and Kaijyuu
 
Status
Not open for further replies.
Top