Basically when a player loses a special building, all his units die.
However I noticed the trigger executes many times at once because I get an array out of bounds error. I even put a show text message for one of the actions to verify and the text message also shows up many times.
You can try to change Unit - Any Unit dies to special building dies and see if it has any effect. But, i have a very similar trigger except my action is a dialog
and when my unit dies the dialog shows up like 4-5 times. I hope somebody has a solution.
Well... I am not 100% certain of the cause than, it might have something to do with the fact you're killing all of those units.
Every unit that is killed it's running the trigger again.
So essentially you're running that trigger a very large amount of times...
but you kind of canceled that with your last statement.
You can try placing a very small wait in the loop for kill unit U such as 0.05 ticks.
As it was suggested (Kind of) earlier I suggest adding a event for each player, each being to the specific building each one owns, this will cut down on condition checks by a lot making it much more efficient as it wont push a kill event and check a condition on a game all about mass killing.
The way I'm reading your trigger, you're not defining what U is before you tell the trigger to kill all of U. You're only checking to see if the dying unit is a type. Try setting U to unit type of triggering unit before your unit group action. I think your action is trying to kill every No Unit in the whole map.
Don't need to define U because the loop sets U for each unit before executing the actions in the loop.
Just in case though, I tried initializing U to something and the error remains.
I don't know what's wrong. I've seen this same exact action in other maps and it works fine.
I used a global variable that keeps track of the amount of times the trigger is called. According the variable, it executes 7 times. I changed the event a bit and got it to say 1 time, but the array out of bounds error still happens. I'm guessing something is causing the trigger to execute multiple times simultaneously.
Anyone know what the cause of the out of bounds error is? I'm guessing it's to loop through the set of units that was already killed as a result of executing again.
I see what you mean. I just tested the trigger using a Lair as the special building - even had one Lair's death trigger the death of other Lairs, and that didn't cause any errors. My only guess was that it had to do with the death of one special building causing a chain of the trigger repeating itself.
I did get an error when I placed 500+ hostile zerglings to be killed on death of a hostile Lair (I tried this with just having one Lair and having three Lairs owned by hostile.) It said "Too many threads." If that's the same error you're getting, maybe it's just the sheer amount of units being killed. If you do figure it out, I'm sure we'd all be interested to know what was wrong.
The number of times this error shows up is equal to the amount of units that died, so that's why im guessing this trigger is somehow executing multiple times simultaneously.
I even changed the event to something like typing a chat message. It still happens.
Yea I just tried something like that due to a conflict with another trigger I completely forgot about. It's another trigger (let's call this trigger T2) with the event "Any unit dies". Let's say T1 is the trigger im talking about in the OP.
I used a global boolean currentlyKillingUnits. T2 has the condition that currentlyKillingUnits is false. T1 sets currentlyKillingUnits to true before it does the loop. After it finishes the loop, it sets the boolean back to false.
The error was still popping up so I put some print statements to see how exactly each step is being ran. Apparently T2 starts executing for each unit that was killed AFTER T1 finishes. It somehow memorizes those deaths while T1 is executing for future triggers to execute.
So now im wondering if there's a way to forget that unit died. I think I can probably use the remove unit action but I'd rather have the death effects happening.
conditions: if b == true than don't run this trigger
set b = true kill unit u set b = false
Untested but this worked in wc3.
That's too hackish for my tastes.
Kept this first bit here for posterity, possible reason/solution starts at ...Hmm*
Try printing out the name of the "Triggering Unit" every time (Convert Game Link to String to Text) the trigger executes (keeping your condition in there). (outside of the loop)
Is the name of the "Triggering Unit" the same every time? IE. does it print out "Special Building" each iteration, or something different.
If it is always "Special Building" I would suspect that the game sees the building dies, runs the trigger. It then runs the loop looking for all of your units. Technically the *dead* building is still one of "your" units as far as the game is concerned, so it sends it a "kill" command again and the loop processes again. (Although why it wouldn't run this infinitely if this were the case, I'm not sure).
If the name of the "Triggering unit" is different everytime, something is goofy with the trigger. Or you have a conflicting trigger elsewhere and the root of the problem isn't here.
... Hmm, after reading this I see that in your loop you're *already* excluding the dead units in your filter!
There's another possibility. It's looping through "units in x owned by y matching z" and setting the variable U. The first iteration works fine, it sets U to, say, unit1, and kills it.
On the second iteration it has to look for the 2nd unit. It performs the check again (This is conjecture, and would be a poorly-coded loop, but it may be what you're experiencing) for units in x owned by y matching z (where 'z' is now *excluding* the dead unit1)
Since the loop is looking for the 2nd unit, but unit 1 is no longer in the array, it actually finds unit 3 - and kills it.
Let's say our array starts out like this:
[0] = Unit1
[1] = Unit2
[2] = Unit3
[3] = Unit4
Since we're in a loop, we have an iterator 'i'.
i = 0
Now, we kill index [i] = Unit1, and our array looks like this:
[0] = Unit2
[1] = Unit3
[2] = Unit4
i = 1
Now, we kill index [i] = Unit3, and our array looks like this:
[0] = Unit2
[1] = Unit4
i = 2
Now, we kill index[i] = ARRAY OUT OF BOUNDS ERROR
Taking your comments and your trigger in isolation - I would expect that this is what is happening.
There may be other conflicting triggers still though. There are two things you can try to do to fix this problem.
1) Change "for each unit" to "pick each unit" and use "Picked Unit" instead of "U". See if this works, if not, go onto #2
2) Where your loop reads Units in X owned by Y matching Z, use a local variable instead. Set the local variable *before* the loop runs to this unit group. Then iterate over the pre-populated unit group so that it isn't performing the filter check every time the loop iterates. (This is more efficient computationally anyway). This way it won't be removing items from your array in the middle of the loop.
Let me know if any of this helps, I can't be certain this is what you're experiencing, but I suspect it is
Basically when a player loses a special building, all his units die.
However I noticed the trigger executes many times at once because I get an array out of bounds error. I even put a show text message for one of the actions to verify and the text message also shows up many times.
Here's the trigger:
I also used another event (unit uses ability) and the same problem happens.
Anyone else have experience with this problem and know how to fix it?
The trigger seems solid (even tested) however are you sure there's no other triggers conflicting with it somehow?
Do you have a revive trigger after they die?
Do you have any triggers that make a ' Special Building ' unit.
Do you have more than one ' special building ' unit?
You can try to change Unit - Any Unit dies to special building dies and see if it has any effect. But, i have a very similar trigger except my action is a dialog and when my unit dies the dialog shows up like 4-5 times. I hope somebody has a solution.
@zachet: Go
@zachet: Go
Nope this is the only trigger that even involves this special building.
Think of it as the bunker in bunker wars. Can't revive it and every player only has one of them.
Interesting because it works perfectly for me...
About how many units do you have on the map at once when this happens?
I tried it for different numbers, even 1 unit or 200 units, same error.
Well... I am not 100% certain of the cause than, it might have something to do with the fact you're killing all of those units.
Every unit that is killed it's running the trigger again.
So essentially you're running that trigger a very large amount of times...
but you kind of canceled that with your last statement.
You can try placing a very small wait in the loop for kill unit U such as 0.05 ticks.
As it was suggested (Kind of) earlier I suggest adding a event for each player, each being to the specific building each one owns, this will cut down on condition checks by a lot making it much more efficient as it wont push a kill event and check a condition on a game all about mass killing.
I just tried instead of any unit dies, I did specific Special Building dies. Same out of bounds error happens.
The way I'm reading your trigger, you're not defining what U is before you tell the trigger to kill all of U. You're only checking to see if the dying unit is a type. Try setting U to unit type of triggering unit before your unit group action. I think your action is trying to kill every No Unit in the whole map.
@VandalD: Go
Don't need to define U because the loop sets U for each unit before executing the actions in the loop.
Just in case though, I tried initializing U to something and the error remains.
I don't know what's wrong. I've seen this same exact action in other maps and it works fine.
I used a global variable that keeps track of the amount of times the trigger is called. According the variable, it executes 7 times. I changed the event a bit and got it to say 1 time, but the array out of bounds error still happens. I'm guessing something is causing the trigger to execute multiple times simultaneously. Anyone know what the cause of the out of bounds error is? I'm guessing it's to loop through the set of units that was already killed as a result of executing again.
I see what you mean. I just tested the trigger using a Lair as the special building - even had one Lair's death trigger the death of other Lairs, and that didn't cause any errors. My only guess was that it had to do with the death of one special building causing a chain of the trigger repeating itself.
I did get an error when I placed 500+ hostile zerglings to be killed on death of a hostile Lair (I tried this with just having one Lair and having three Lairs owned by hostile.) It said "Too many threads." If that's the same error you're getting, maybe it's just the sheer amount of units being killed. If you do figure it out, I'm sure we'd all be interested to know what was wrong.
This is the exact error im getting:
The number of times this error shows up is equal to the amount of units that died, so that's why im guessing this trigger is somehow executing multiple times simultaneously.
I even changed the event to something like typing a chat message. It still happens.
The easiest way is to..
GLOBAL boolean b = false
conditions: if b == true than don't run this trigger
set b = true kill unit u set b = false
Untested but this worked in wc3.
Yea I just tried something like that due to a conflict with another trigger I completely forgot about. It's another trigger (let's call this trigger T2) with the event "Any unit dies". Let's say T1 is the trigger im talking about in the OP.
I used a global boolean currentlyKillingUnits. T2 has the condition that currentlyKillingUnits is false. T1 sets currentlyKillingUnits to true before it does the loop. After it finishes the loop, it sets the boolean back to false.
The error was still popping up so I put some print statements to see how exactly each step is being ran. Apparently T2 starts executing for each unit that was killed AFTER T1 finishes. It somehow memorizes those deaths while T1 is executing for future triggers to execute.
So now im wondering if there's a way to forget that unit died. I think I can probably use the remove unit action but I'd rather have the death effects happening.
That's too hackish for my tastes.
Try printing out the name of the "Triggering Unit" every time (Convert Game Link to String to Text) the trigger executes (keeping your condition in there). (outside of the loop)
Is the name of the "Triggering Unit" the same every time? IE. does it print out "Special Building" each iteration, or something different.
If it is always "Special Building" I would suspect that the game sees the building dies, runs the trigger. It then runs the loop looking for all of your units. Technically the *dead* building is still one of "your" units as far as the game is concerned, so it sends it a "kill" command again and the loop processes again. (Although why it wouldn't run this infinitely if this were the case, I'm not sure).
If the name of the "Triggering unit" is different everytime, something is goofy with the trigger. Or you have a conflicting trigger elsewhere and the root of the problem isn't here.
... Hmm, after reading this I see that in your loop you're *already* excluding the dead units in your filter!
There's another possibility. It's looping through "units in x owned by y matching z" and setting the variable U. The first iteration works fine, it sets U to, say, unit1, and kills it.
On the second iteration it has to look for the 2nd unit. It performs the check again (This is conjecture, and would be a poorly-coded loop, but it may be what you're experiencing) for units in x owned by y matching z (where 'z' is now *excluding* the dead unit1)
Since the loop is looking for the 2nd unit, but unit 1 is no longer in the array, it actually finds unit 3 - and kills it.
Let's say our array starts out like this:
Since we're in a loop, we have an iterator 'i'.
i = 0
Now, we kill index [i] = Unit1, and our array looks like this:
i = 1
Now, we kill index [i] = Unit3, and our array looks like this:
i = 2
Now, we kill index[i] = ARRAY OUT OF BOUNDS ERROR
Taking your comments and your trigger in isolation - I would expect that this is what is happening.
There may be other conflicting triggers still though. There are two things you can try to do to fix this problem.
1) Change "for each unit" to "pick each unit" and use "Picked Unit" instead of "U". See if this works, if not, go onto #2
2) Where your loop reads Units in X owned by Y matching Z, use a local variable instead. Set the local variable *before* the loop runs to this unit group. Then iterate over the pre-populated unit group so that it isn't performing the filter check every time the loop iterates. (This is more efficient computationally anyway). This way it won't be removing items from your array in the middle of the loop.
Let me know if any of this helps, I can't be certain this is what you're experiencing, but I suspect it is
Unless I'm not understanding what your asking for, wouldn't this work: