So recently today I ran into a pretty major issue.
When designing my map, I broke everything down into small triggers with specific conditions. I added a few new triggers, and boom. Trigger errors all over the place.
"Too many threads."
So I went and made a looping trigger that would just run as many times as the game would allow. It ran 240 times.
Is 240 the maximum number of threads you can have active in a sc2 map?
Also I'd like more information on proper trigger coding over how to minimize your thread count if anyone feels like sharing. Thank you!
If you have 240 separate threads you need to use fewer loops with wait in them and make better use of events. Keep in mind that any time you use wait in a trigger (including using it indirectly) it causes that trigger to fork a new thread.
If you have 240 separate threads you need to use fewer loops with wait in them and make better use of events. Keep in mind that any time you use wait in a trigger (including using it indirectly) it causes that trigger to fork a new thread. Generally speaking, Wait should only be used in triggers which will only ever have a single instance running at a time. Not only will that lower your thread count, but it'll decrease the risk of race conditions.
No that's the opposite of what I said. Use events, not loops. Frankly how in the living hell do you have 30 different triggers for each item in your game? The hell do they all do? That right there should be a huge signal that there's something deeply wrong with whatever approach you've taken.
Maybe if you want to post a couple examples of your triggers we could see if there's any fundamental problems or it's just a matter of complexity scaling beyond what the SC2 engine can reasonably handle.
My map makes heavy use of behaviour stacks, and I can't get effects to work fully beyond 1 stack.
For example, you pick an item up. It applies a behaviour that increases health. If I attach an initial effect to the behaviour of the item, the effect will only apply on the first stack, and not subsequent ones.
Place the same effect in both the Effect - Initial field and also in the Refresh Effect. Also, make sure you have set the Maximum Stacks field to be more than 1.
Place the same effect in both the Effect - Initial field and also in the Refresh Effect. Also, make sure you have set the Maximum Stacks field to be more than 1.
If I may say so: OH JESUS 240 THREADS CREATED AT JUST AN INSTANCE!
Ok, well. There's nothing wrong in splitting larger triggers into small chunks, but when you do so you should make own Functions and put the splitted actions in there, then call all the actions with a single trigger.
If I may say so: OH JESUS 240 THREADS CREATED AT JUST AN INSTANCE!
If you've played Catalyst, I had triggers running for each item type. 5 triggers running per item you pick up. When you die, all those triggers would run for each item as it was added back to your vehicle. You could have 26 items max. Then throw in the scoreboard and revive triggers. It's about 130 total.
All worked fine, if a little inefficient. However, if two players died at the same time...
Anyway it's fixed now. I've re-done a lot of the triggers in the data editor. The only one I can't do in data is adding weapons properly after the first.
240 is a lot actually. You need to improve and merge some thread. Or use data editor.
Edit: Or properly turn them on and off when necessary
Yeah it's down to 1 per item, or 26 now.
I also noted that turning a trigger off and back on again does nothing unless you apply a wait. For example;
I turn trigger "Item Check" off.
I create an item.
I turn trigger "Item Check" on.
This does nothing. The other trigger won't even run until the current trigger's actions are complete (assuming no wait), making turning it off and back on again pointless.
Turn off
Create item
Wait 0.1
Turn on
This works, though is impractical in most situations.
So recently today I ran into a pretty major issue.
When designing my map, I broke everything down into small triggers with specific conditions. I added a few new triggers, and boom. Trigger errors all over the place.
"Too many threads."
So I went and made a looping trigger that would just run as many times as the game would allow. It ran 240 times.
Is 240 the maximum number of threads you can have active in a sc2 map?
Also I'd like more information on proper trigger coding over how to minimize your thread count if anyone feels like sharing. Thank you!
If you have 240 separate threads you need to use fewer loops with wait in them and make better use of events. Keep in mind that any time you use wait in a trigger (including using it indirectly) it causes that trigger to fork a new thread.
To be more specific over my issue;
My hero dies. My hero has upwards of 20 items. There's triggers that fire off each item, around 30 triggers.
That's how I got to 240 threads.
I re-wrote most of my map to merge the item responce triggers together, and it seems to work now.
I'm just not sure if a 300 action trigger is really realistic. It works fine offline, but I daren't upload it.
So I'm okay to use "Loop forever" triggers?
No that's the opposite of what I said. Use events, not loops. Frankly how in the living hell do you have 30 different triggers for each item in your game? The hell do they all do? That right there should be a huge signal that there's something deeply wrong with whatever approach you've taken.
Maybe if you want to post a couple examples of your triggers we could see if there's any fundamental problems or it's just a matter of complexity scaling beyond what the SC2 engine can reasonably handle.
Are you sure you couldn't implement your item's effects using the Data Editor?
My map makes heavy use of behaviour stacks, and I can't get effects to work fully beyond 1 stack.
For example, you pick an item up. It applies a behaviour that increases health. If I attach an initial effect to the behaviour of the item, the effect will only apply on the first stack, and not subsequent ones.
Place the same effect in both the Effect - Initial field and also in the Refresh Effect. Also, make sure you have set the Maximum Stacks field to be more than 1.
Thanks for this. Worked perfectly.
@Eiviyn: Go
If I may say so: OH JESUS 240 THREADS CREATED AT JUST AN INSTANCE!
Ok, well. There's nothing wrong in splitting larger triggers into small chunks, but when you do so you should make own Functions and put the splitted actions in there, then call all the actions with a single trigger.
If you've played Catalyst, I had triggers running for each item type. 5 triggers running per item you pick up. When you die, all those triggers would run for each item as it was added back to your vehicle. You could have 26 items max. Then throw in the scoreboard and revive triggers. It's about 130 total.
All worked fine, if a little inefficient. However, if two players died at the same time...
Anyway it's fixed now. I've re-done a lot of the triggers in the data editor. The only one I can't do in data is adding weapons properly after the first.
240 is a lot actually. You need to improve and merge some thread. Or use data editor.
Edit: Or properly turn them on and off when necessary
Regardless of how badly things need to be coded to need this many threads...its a good thing to know what the actual upper limit is.
Yeah it's down to 1 per item, or 26 now.
I also noted that turning a trigger off and back on again does nothing unless you apply a wait. For example;
I turn trigger "Item Check" off.
I create an item.
I turn trigger "Item Check" on.
This does nothing. The other trigger won't even run until the current trigger's actions are complete (assuming no wait), making turning it off and back on again pointless.
Turn off
Create item
Wait 0.1
Turn on
This works, though is impractical in most situations.
@Eiviyn: Go
usually we wait 0.0 seconds :), it translate to 1/32s. the rate of execution require some cases for a wait to apply, its annoying sometime
Yeah and 1/32th of a second more or less translates into about 50 thread's worth of lag, so you're not even really gaining anything.