Question about "temporary" variables

staind25

TH.net Regular
Reaction score
7
So I started using Temp variables for memory leak removal...my question is, do I need multiple instances of these variables, or as long as there are no waits in the trigger, can I use the same one each time?

For example, if both of these triggers ran at the same time, would I have issues?

Trigger:
  • Actions
    • Set TempPoint = (Position of (Target unit of ability being cast))
    • Unit - Create 1 Dummy Druid Unit for (Owner of (Triggering unit)) at TempPoint facing TempPoint
    • Custom script: call RemoveLocation( udg_TempPoint )
    • Unit - Order (Last created unit) to Orc Raider - Ensnare (Target unit of ability being cast)
    • Unit - Add a 4.00 second Generic expiration timer to (Last created unit)
    • Trigger - Turn on Roots Break <gen>


Trigger:
  • Loop - Actions
    • Unit - Cause (Triggering unit) to damage (Picked unit), dealing (35.00 x (Real((Level of Frost Nova (Triggers) for (Triggering unit))))) damage of attack type Spells and damage type Cold
    • Set TempPoint = (Position of (Picked unit))
    • Unit - Create 1 Dummy Mage Unit (Frosty Ensnare) for (Owner of (Triggering unit)) at TempPoint facing TempPoint
    • Custom script: call RemoveLocation( udg_TempPoint )
    • Unit - Order (Last created unit) to Orc Raider - Ensnare (Picked unit)
    • Unit - Add a 4.00 second Generic expiration timer to (Last created unit)


The biggest difference between the two triggers is that they use different spells. So, my question is, if both spells fire at the same time, will the variables clash, or will they run correctly (Notice I'm using the same TempPoint variable in both)?

Just trying to wrap my brain around successfully removing leaks :) Thanks!
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
You should be fine. There's no such thing as triggers "running at the same time" - all operations happen in a sequence*. If both triggers have the same event, one will run first and one will run second. That order isn't really possible to determine (at least when using the GUI), but each trigger will run in sequence until complete.

If one of those triggers had a wait between the creation of the point and the removal of the point, something could happen in that time and mess things up, but that's not the case here. :)

*However, sometimes that sequence is not so obvious. While it couldn't really be called "running at the same time", it's possible for another trigger to have its event run due to actions in the original trigger, and then the original trigger's actions will be put on hold while the 2nd trigger's actions all** run until complete, at which point the original trigger's actions would resume. That can cause a problem with overwritten variables, like you were worried about.

In this case, for example, if one of those trigger's event was "A unit enters (Playable map area)", the action of creating a unit could cause the other trigger to immediately run. If that's the case, it would be better to use separate temp variables. If not, then it's fine the way you've done it.

**Except, of course, if the trigger has a wait, or if it also gets "interrupted" by a third trigger. ;)
 

staind25

TH.net Regular
Reaction score
7
Thanks for the explanation! Much appreciated.

If both triggers have the same event, one will run first and one will run second.

^ I find this very interesting...I knew that ONE trigger by itself runs sequentially, but I thought two triggers with the same event would run at the exact same time. I guess processors can't multitask that well? XD

One more question, if you don't mind:

When it comes to loops, I know you can choose to use either Integer A, Integer B, or your own variable. If you choose Integer A, can you only use that in ONE loop? Will using Integer A in two loops clash? Just wondering...there must be some reason there's A and B.

Thanks again :)
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
^ I find this very interesting...I knew that ONE trigger by itself runs sequentially, but I thought two triggers with the same event would run at the exact same time. I guess processors can't multitask that well? XD
Well, they'll both start and finish before anything more happens in the game, pretty much "instantaneously"...but their actions will be processed in sequence.

Processors can multitask, if the program is written to allow it. ;) Multithreading is a headache. Leave it to the programmers; you (probably!) don't want to deal with that while triggering.

If you choose Integer A, can you only use that in ONE loop? Will using Integer A in two loops clash? Just wondering...there must be some reason there's A and B.
You mean, loops within loops? Then yes, that would conflict: Integer A and Integer B are just preset global variables that are used for counting the loop. Doing one after the other is fine, although having an action within a loop cause another trigger to run (like I mentioned before) which itself wants to use the same loop variable would be a problem.
 

staind25

TH.net Regular
Reaction score
7
Ah, yes, I understand... And yeah, haha, I'm going into computer science in the fall, but I doubt I'll get into hardware! That makes sense though...that's kind of what I figured...it's a software limitation rather than a hardware limitation.


No, I mean two loops that may end up running at the same time, but since you've just shown me that two triggers can run "at the same time" and still not cause issues, the same should apply here :) Thank you.

It's good to know though, that I can't have loops within loops using the same variable...good point.
 

staind25

TH.net Regular
Reaction score
7
Oh by the way, thank you for your GDD system! I'm using it for this spell I'm currently working on. It saved me a lot of headache!
 

Slapshot136

Divide et impera
Reaction score
471
I guess processors can't multitask that well? XD

wc3 was released in 2002, 8 years ago - there weren't that many multi-core processors then (or even ones with HT) if any outside of server processors, so the game itself wasn't coded to benefit from multiple cores

and "multitasking" for a computer means doing 10% of A, then doing 10% of B, and so on and so forth in such as way that you the user don't notice, not doing A and B simultaneously, unless it was made in a way to benefit from the above, which wasn't the case in 2002 for games (actually it still isn't the case for 90% of games)
 

staind25

TH.net Regular
Reaction score
7
wc3 was released in 2002, 8 years ago - there weren't that many multi-core processors then (or even ones with HT) if any outside of server processors, so the game itself wasn't coded to benefit from multiple cores

and "multitasking" for a computer means doing 10% of A, then doing 10% of B, and so on and so forth in such as way that you the user don't notice, not doing A and B simultaneously, unless it was made in a way to benefit from the above, which wasn't the case in 2002 for games (actually it still isn't the case for 90% of games)

Good point. Multi-threading was around though XD

That makes sense. I think I demonstrated a little more ignorance in my previous post than I really suffer from...I do have a decent idea of how hardware works...but I still appreciate the clarification :)

I was just under the impression that perhaps if two triggers fired at the exact same time, they might clash. But I guess not. And yes, I realize that the "sequential order" is completely unnoticeable to us simply because it is SO fast. Thank you again :)
 

Bogrim

y hello thar
Reaction score
154
The reason for we call them "temporary" variables is because of this very line:
Trigger:
  • Custom script: call RemoveLocation( udg_TempPoint )

You literally destroy the variable's data. You do so in order to minimize the amount of memory needed to run the game, but none the less you need to understand when you should use a temporary variable and when you need create a specific variable.

Waits are good examples of triggers demanding either specific or temporary variables because if the data needs to be saved over the duration of the wait action, using the same "temporary" global variable would chance another trigger firing and destroying the variable's data before the wait action comes to an end, therefore bugging your trigger.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top