| 11-17-2002, 11:12 PM | #1 |
I just had a strange thought. If I understand correctly, when you call one trigger from another, the calling trigger sits someplace in memory, waiting to resume: trigger1 event: unit is given an order with no target action: if order = stop then run trigger2, else do nothing game display: hold order given --------------------------- trigger2 action: game display: stop order given As written, when you run the game, and give a stop order, you see the following: stop order given hold order given ok, cool, I can convert the first trigger into custom text, and add a "skip remaining actions" action to it (which becomes "return" in custom text). Then, each order will generate the right message. My question is this: in my map, I have literally dozens of triggers being called with if...then actions. Indeed, some of the called triggers in turn call the original trigger (though presumably a different copy of it in memory), which then will itself call some of these other triggers again, etc, etc. I can imagine that over enough time, many, many copies of each trigger are accumulating in memory. As far as I have tested, this doesn't seem to be a problem. Will it become one eventually? If so, how can I deal with this (or prevent it)? |
| 11-17-2002, 11:18 PM | #2 |
It depends on how you set it up. You should know though that if you call another trigger within a trigger, the first trigger _moves on_ right away, it doesn't wait for the second one to finish (i.e. wait actions in the second trigger won't cause it to wait to do actions in the first trigger). Also, it does call a _new_ instance of the trigger, you're right. This won't be a problem as long as you don't do something like this: Trigger 1: Call trigger2 Trigger 2: Call trigger1 ;) As long as there's some condition so that it stops, you'll be okay. Also, once a trigger has completed all it's actions, it disappears, even if it called other triggers. So no, alot won't accumulate in memory (since the first trigger doesn't wait for the second to finish) The one ripple in this behavior is that the second trigger _can_ use function referring to stuff in the first trigger, i.e. Triggering Player, and Triggering Unit will still work in the second trigger, even if the first has already gone away. Have fun =) |
| 11-18-2002, 12:36 AM | #3 |
That's exactly what I was looking for. Thanks a million. In the same vein, two other issues. My experience seems to be that there's a "grace period" in running parallel triggers. If I have something like this: trigger1: event - elapsed game time 5 seconds actions - run trigger2 if Q = 20 then display "20", else display "error" trigger2 set Q = 20 not only will it work, but even if I add certain non-wait commands in trigger2 *before* I set Q, it will still work: trigger2 actions: for a = 1 to 40 set a_useless_variable = (integer A * 4) fade in, out over 2 seconds set Q = 20 Testing this, trigger2 seems to run in its entirety before trigger1 can even reach its next line. To be sure, any "wait" command in trigger2 lets trigger 1 "win" the race, but trigger2 seems to get major cpu cycle priority between the two. Can anyone confirm this, or give an explanation? Also, suppose I wanted to have something like this: if a is true then run a_trigger_with_a_long_execution if b is true then run another_trigger_with_a_long_execution if c is true then run yet_another_trigger_with_a_long_execution display a dialog where, a, b, and c can all be true. I've tested, and as you say, the dialog will be displayed almost immediately (all three side triggers have wait functions in them, so the above would not apply). What would be the best way to have all three triggers run in order (as needed) and then have the dialog pop up? |
| 11-18-2002, 01:18 AM | #4 |
I'm a little confused, give all your triggers events and that'll help =) |
| 11-18-2002, 02:19 AM | #5 |
Let's see. I don't really have a particular trigger in mind. The first example I gave below as a "grace period" example is a test case. I'm curious to see just how the game treats the spawned trigger compared with the "spawner" trigger. In the game I'm making, I'd hate to do a mathematical function in a spawned trigger, only to have the check for that math in the original trigger happen first. trigger1: event - hero owned by player 1 gets "holy grail" item event - hero owned by player 2 gets "holy grail" item actions: run trigger2 if grail = 1 then display to player 1 "congratulations", else display "error" trigger2 actions: for a = 1 to 40 set a_useless_variable = (integer A * 4) fade in, out over 2 seconds if owner of activeunit = player 1 then set grail = 1 You mentioned that trigger1 should continue to run after it calls trigger2. BUt I can verify that trigger1 will display "congratulations" when this is run in warcraft, which means that trigger2 in its entirety must have finished before trigger1 even got to its next line. IMHO, this is a good thing, but I'm trying to feel out the "rules" of it. A "wait" command in trigger2 will result in "error" as the display in trigger1, indicating that trigger1 indeed doesn't wait for trigger2 to finish, but simple math seems to happen in trigger2 even before trigger1 has a chance to run. For the second issue, I'm creating a turn based game. At the beginning of each turn, one or more events may happen, followed by a menu being displayed to the user consisting of a list of actions. But *before* the turn begins, one or more events from the last turn may happen. This involves a number of math- and graphic-containing triggers (which also have wait commands in them, meaning that the originating trigger *will* continue to run): previous turn ends ---> run turn trigger turn trigger: if spell1 is active, then run [a graphic intensive trigger1] if spell2 is active, then run [a graphic intensive trigger2] if spell3 is active, then run [a graphic intensive trigger3] run newturn trigger newturn trigger: display menu for player1 As written, the menu will be displayed (the very last action) almost immediately, long before any of the earlier actions have a chance to run. I'd love to avoid that in some simple way, especially since there might be a large number of if....then statements running before that point. I'd love for each graphic trigger to run in turn, if possible. |
| 11-20-2002, 06:34 AM | #6 |
For what it's worth, I have a makeshift solution. For anyone following, I've been trying to have a trigger call a second trigger, suspend operation while the called trigger runs, and then resume, when the called trigger is finished. Because the second trigger is conditionally run, I can't assume that it will always run (otherwise the solution would be easy - simply use a wait command). As dataangel pointed out, JASS doesn't work like this by default (normally, the first trigger will continue running). Here's my solution to this: Trigger1 Actions: set X = 0.00 set Y = 0.00 [other actions] if condition x is true set X = 3.00, else do nothing if condition x is true set Y = 3.00, else do nothing //of course in custom text, this can be a single if...then for each (integer A) from 1 to 500: if X = 0.00 and Y = 0.00 do nothing, else wait .1 seconds [other actions] Trigger2 Event: Y becomes equal to 3.00 Conditions: X = 3.00 [the order is important, since otherwise Y will still be zero when X is checked] Actions: [whatever actions run in this trigger] set X = 0.00 set Y = 0.00 At least in the simple case I've written here, the first trigger will call the second trigger, and then (as expected) wait up to 50 seconds for a resumption signal from the second trigger. Normally, I'd expect CPU usage to take at least a small hit from something like this, but at least in the simple test-map I made it was unnoticable. In custom text, I suppose, I could reset counting variable a to zero in each, making it go fovever, but this is better, since it provides a guarantee that the first trigger will continue (granted 50 seconds is *forever* if nothing else is happening), even if I screw up in the second trigger. |
