| 07-31-2003, 04:14 PM | #1 |
Hello, I'm getting into some more sophisticated trigger development and I'd like to write some general purpose triggers that take input from other triggers. For example, I'd like to write a function called SpawnUnitsAtRegionX, which could spawn units at any supplied region. At the moment, I'm doing this by having a variable called "RegionX" that is set by one trigger, which then immediately calls SpawnUnitsAtRegionX. This works great. But I ws wondering - does this work all the time? Anyone who has done multithreaded programming must see what I'm getting at here. If a whole lot of triggers all go off at once and one of them sets RegionX to one place, but gets preempted by another before calling SpawnUnitsAtRegionX, and the preempting trigger changes RegionX to some other place, when the game engine returns to executing the first script, the units are going to spawn in the wrong place. Intuitively, it makes sense to me that the Warcraft scripting language be non-preemptive - triggers run to completion before another one is allowed to fire. But maybe the trigger engine is multithreaded to allow for concurrent execution of multiple triggers? Does anyone know for sure? Also, what happens if one trigger is in the "Wait for X seconds" state? It seems like other triggers should be able to fire during this interval. Is this true? To sum up my entire question: Are triggers gauranteed to run to completion, and under what circumstances are they not? Thanks. |
| 07-31-2003, 04:33 PM | #2 |
Use the trigger-queue to queue up triggers, so they run after each other's completion. |
| 07-31-2003, 04:46 PM | #3 |
From my experiences, a trigger is allowed to run until it is finished without any interruption from either the game or other triggers. If you execute the Wait-command (TriggerSleepAction in JASS) then other triggers are allowed to run and can destroy any globals you might be using in the trigger, as well as event responses (e.g. GetTriggeringUnit().) |
