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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top