• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Can your trigger (if conditions) be too long?

Status
Not open for further replies.
Level 2
Joined
Dec 11, 2020
Messages
11
Hi, as the title implies, can you have a trigger that has too many functions, in particular if conditions?

I'm aware of the 1ghz limitation of memory usage, but I'm pretty sure that that applies to simultaneous actions or functions being called.

But for this specific type of trigger I had to use a work-about to find the hero's primary attribute.

(Since there's no function in GUI or Jass that I can recall)

I'm basically checking one by one if the hero chosen is a [specific] hero and then adding them to a unit group so I can call them later.

Eg.

If (Unit-type of (Triggering unit)) Equal to Archmage)
Then Unit Group - Add (Triggering unit) to IntHeroes
If (Unit-type of (Triggering unit)) Equal to Blood Mage)
Then Unit Group -Add (Triggering unit) to IntHeroes
...
You get the idea.

Of course if anyone has a better way around this, I'd be more than welcome to hear it.
 
Level 12
Joined
Nov 3, 2013
Messages
989
I've seen insanely long lists of if then else chains so it should be fine


But if you want to make it a bit easier on yourself you could first make a unit type array variable: myUnit[1], myUnit[2], myUnit[3], etc. it's a single variable but because of the array you can use it as if you had made thousands of variables


So first of all, what I would do is make a separate trigger which just adds all your unit types into unit array(s) one by one so you can loop through them.

  • set unit type variable myUnit[1] = Archmage
  • set unit type variable myUnit[2] = Blood Mage
  • etc.
Then there's a few options, e.g. hashtable is probably the best, but it can be a bit difficult.

I think the easiest way here would be to just have 3 "lists".

So instead of doing what I did earlier, it would be like this

  • set unit type variable intHero[1] = Archmage
  • set unit type variable intHero[2] = Blood Mage
  • etc.
  • set unit type variable agiHero[1] = Blademaster
  • set unit type variable agiHero[2] = Shadowhunter
  • set unit type variable strHero[1] = Paladin
  • set unit type variable strHero[2] = Death Knight
Then you in your trigger where you want to find out if the unit type of the hero is int/agi/str, you just loop through the 3 lists

  • set tempUnit = (Triggering Unit)
  • for loop integer A from 1 to intHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == intHero[(loopA)] then
      • Unit Group - Add tempUnit to IntHeroes
      • custom script: exitwhen true
    • endif
  • endloop
  • for loop integer A from 1 to agiHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == agiHero[(loopA)] then
      • Unit Group - Add tempUnit to agiHeroes
      • custom script: exitwhen true
    • endif
  • endloop
  • for loop integer A from 1 to strHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == strHero[(loopA)] then
      • Unit Group - Add tempUnit to strHeroes
      • custom script: exitwhen true
    • endif
  • endloop
Though if the heroes are already split into 3 different lists depending on primary attribute like this then you might not even need to add them into unit groups like that.
 
Level 2
Joined
Dec 11, 2020
Messages
11
I've seen insanely long lists of if then else chains so it should be fine


But if you want to make it a bit easier on yourself you could first make a unit type array variable: myUnit[1], myUnit[2], myUnit[3], etc. it's a single variable but because of the array you can use it as if you had made thousands of variables


So first of all, what I would do is make a separate trigger which just adds all your unit types into unit array(s) one by one so you can loop through them.

  • set unit type variable myUnit[1] = Archmage
  • set unit type variable myUnit[2] = Blood Mage
  • etc.
Then there's a few options, e.g. hashtable is probably the best, but it can be a bit difficult.

I think the easiest way here would be to just have 3 "lists".

So instead of doing what I did earlier, it would be like this

  • set unit type variable intHero[1] = Archmage
  • set unit type variable intHero[2] = Blood Mage
  • etc.
  • set unit type variable agiHero[1] = Blademaster
  • set unit type variable agiHero[2] = Shadowhunter
  • set unit type variable strHero[1] = Paladin
  • set unit type variable strHero[2] = Death Knight
Then you in your trigger where you want to find out if the unit type of the hero is int/agi/str, you just loop through the 3 lists

  • set tempUnit = (Triggering Unit)
  • for loop integer A from 1 to intHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == intHero[(loopA)] then
      • Unit Group - Add tempUnit to IntHeroes
      • custom script: exitwhen true
    • endif
  • endloop
  • for loop integer A from 1 to agiHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == agiHero[(loopA)] then
      • Unit Group - Add tempUnit to agiHeroes
      • custom script: exitwhen true
    • endif
  • endloop
  • for loop integer A from 1 to strHeroesNumber
    • if then else multiple actions
    • if unit type of tempUnit == strHero[(loopA)] then
      • Unit Group - Add tempUnit to strHeroes
      • custom script: exitwhen true
    • endif
  • endloop
Though if the heroes are already split into 3 different lists depending on primary attribute like this then you might not even need to add them into unit groups like that.

I'll try what you suggested, thanks a bunch!
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
I'm aware of the 1ghz limitation of memory usage
Hertz - Wikipedia
Gigabyte - Wikipedia

Legacy Warcraft III was limited to 2 GB of memory due to being a x86 application without large address awareness. Shortly before Reforged it was made large address aware allowing up to 4 GB of memory on 64 bit Windows. Now Warcraft III is x86-64 and large address aware so has no practical memory limit. It may still have an artificial memory limit due to how it was coded.
Hi, as the title implies, can you have a trigger that has too many functions, in particular if conditions?
If they are all executed immediately without a pause of sorts then yes. You can hit the thread op limit which will cause the trigger thread to crash preventing execution beyond that point. This limit is quite big, especially currently, but can still be easily hit with loops.
 

zam

zam

Level 3
Joined
Jan 1, 2021
Messages
31
Hertz - Wikipedia
Gigabyte - Wikipedia

Legacy Warcraft III was limited to 2 GB of memory due to being a x86 application without large address awareness. Shortly before Reforged it was made large address aware allowing up to 4 GB of memory on 64 bit Windows. Now Warcraft III is x86-64 and large address aware so has no practical memory limit. It may still have an artificial memory limit due to how it was coded.

If they are all executed immediately without a pause of sorts then yes. You can hit the thread op limit which will cause the trigger thread to crash preventing execution beyond that point. This limit is quite big, especially currently, but can still be easily hit with loops.
Correct me if i'm wrong but all he asked about is the If statements never did he say Loops. If statements won't even reach 5% of OP Limit no matter how much you have of then.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Correct me if i'm wrong but all he asked about is the If statements never did he say Loops. If statements won't even reach 5% of OP Limit no matter how much you have of then.
A very long sequence of if statements should still be affected by the op-limit. If the required length of the sequence is practically obtainable is another question, but possibly with programmatically generated code it could be hit. Additionally the complexity of the condition statement also counts towards the op-limit and if it is a function call then that function may contain a loop that could potentially be prone to hitting the op-limit.
 
Level 2
Joined
Dec 11, 2020
Messages
11
Correct me if i'm wrong but all he asked about is the If statements never did he say Loops. If statements won't even reach 5% of OP Limit no matter how much you have of then.

Yes, I was referring to If statements without loops - I wanted to know if you can hit the limit with them.

A very long sequence of if statements should still be affected by the op-limit. If the required length of the sequence is practically obtainable is another question, but possibly with programmatically generated code it could be hit. Additionally the complexity of the condition statement also counts towards the op-limit and if it is a function call then that function may contain a loop that could potentially be prone to hitting the op-limit.

Thanks for elaborating on the limit. I only saw a post mentioning "1ghz memory limit", but it was very brief.
 
Level 16
Joined
May 2, 2011
Messages
1,345
If (Unit-type of (Triggering unit)) Equal to Archmage)
Then Unit Group - Add (Triggering unit) to IntHeroes
If (Unit-type of (Triggering unit)) Equal to Blood Mage)
Then Unit Group -Add (Triggering unit) to IntHeroes
...
You get the idea.

Of course if anyone has a better way around this, I'd be more than welcome to hear it.
Where is the else?
If you Nest your second IF inside the Else, your code will be much more effecient. If you do that, as long as one condition is met, code will stop. if the IF statements are separate, your trigger will needlessly go through all of them.
 
Status
Not open for further replies.
Top