HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Concurrency in Triggers

09-08-2002, 09:20 PM#1
FM_TertiaryEye
Hey, Does anyone know if triggers in this API are serialized? Meaning, can they execute concurrently? (god I hope not).

I'm having players choose units by moving some acolytes to 7 separate regions and then creating the units they represent somewhere esle and adding the last created unit into an array idexical of the player who initiated the trigger.

If the events can run concurrently, then that means that with (extremely) good timing, a player can get a reference to the wrong character.

Thanks,
Jason
09-08-2002, 09:35 PM#2
Guest
They do, if you use any sort of waits. Normally the triggers would run 1 at a time, line by line, even if the events that trigger them happen at the exact same time.

If you have a wait, while that wait time is running another trigger can run at that time, which can screw you up if you were to use a variable that could be changed.

If you do

Create 1 [unit] at ......
Set UnitArray[integer] = last created unit.

Then there shouldn't be any problem.

However, if you did

NumUnits = NumUnits + 1
Wait 2 seconds
Create 1 [Unit] at .....
Set UnitArray[NumUnits] = Last Created unit

Then you could run into problems where NumUnits is increased before again before it is actually used to set the array.

If you are wanting to have triggers run in order with waits, one way to ensure that they run in order is to use a Trigger queue.
09-09-2002, 06:24 PM#3
FM_TertiaryEye
Someone give that man a promotion! Thank you for the knowledgable explination, it was very helpful.

jason
09-10-2002, 04:00 PM#4
CheshireKatt
Out of curiousity, how does this relate to running other triggers within triggers?

Trigger - Run Trigger (I assume whether it checks conditions or not is irrelevant for purposes of synchronous operation)
Trigger - Add Trigger to Trigger Queue

I'm assuming Trigger - Run Trigger runs within the current one, whereas Add Trigger to Trigger Queue will stick it at the end of the current pile of triggers waiting to be run (or is the queue only for triggers explicitly added with Trigger - Add Trigger to Trigger Queue, and normal triggers are kept in their own special queue?)

For example, I have (making this up as I go):

Trigger 1:
Event: Unit owned by Player 1 (Red) dies
Unit owned by Player 2 (Blue) dies
Action: For (Integer A) 1 to 10 Do Trigger - Run Trigger "Trigger 2"

Trigger 2:
Action: Game - Display Name of (Triggering Player) + String(Integer A) to All Players

Let's say Player 1 and Player 2 both have 1 unit, and they both die simultaneously (a Goblin Sapper Kabooms on them, for example).

Will this set of triggers run in sequence, or are we going to have problems with the For loop's Integer A getting changed somewhat unpredictably? Or will Trigger 1 fire for one of the players, call Trigger 2 10 times printing that player's name and a number, then do the exact same for the other player?

Obviously, using Add Trigger to Trigger Queue here would be bad, as there's no telling who (Triggering Player) will be when the trigger finally gets around to executing.

--CheshireKatt
09-10-2002, 07:24 PM#5
h0pesfall
Hey yo Cheshire it's me, o)ZZzz :P
and uhm, well can't help you sorry :P just want to say hi
09-10-2002, 07:41 PM#6
Guest
In my testing, they will ALWAYS run in sequence. The only thing that would stop this was a wait.

I also tried to see if A very long loop would get it to go out of sequence, and I've found that it doesn't, however if a Loop is too long (I'm talking about 7000-10000 passes through), it will just stop working and move on to the next action.
09-11-2002, 05:35 PM#7
Guest
Any idea about my problem with an Enum function crapping out after a Sleep?

I'm using a ForGroup, and in the function it iterates for each member of the group I've got a Sleep. Nothing in that function executes after the Sleep.

Just wondering if you had any ideas.

Thanks.
09-11-2002, 11:12 PM#8
dataangel
I had that sleep problem once, not sure how to fix. Try waiting a really long time, could be a glitch that causes wait to go on forever.

By default triggers run in sequence, unless you add them to the trigger queue. (then they run independently of all other triggers I'm pretty sure)
09-12-2002, 03:55 AM#9
h0pesfall
heaven, try adding a short wait of like 0.02 seconds before and/or after the action that casts sleep.
that solved alot of my similar trigger freezing problems