• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Em I using variables wrong?

Status
Not open for further replies.
Level 3
Joined
Nov 12, 2018
Messages
43
I just want to know, if I'm currently making a mistake, or if I can keep going as I do. My problem (maybe):
I use a couple of variables (udg_) in almost all of my triggers. Stuff like temporary locations, units, groups... I properly remove/destroy them after use, but I'm still worried, that this habbit will cause bugs later on. Do you guys see or know about any problems with this method?

I could imagine, that a trigger might use wrong information stored in a variable, because it was set befor in another trigger and not destroyed/removed in between. Or is EVERY trigger in Wc3 executed one after another and never simultaneously?

Should I get used to work with locals instead? (if there is a problem)
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
I remember that it is a pre-emptive system... So it would execute code one after another. The problem, if you use global variables, is if a thread gets executed while your code's thread hasn't finished yet and the variable you are using is also used in that newly spawned thread, then the value stored might get overwritten by the spawned thread... I'm too rusty with this so I'm sorry that I couldn't explain it any better. If you don't need the data to be accessible outside the function block you are using it, then I'd say use a local one.

EDIT: Clarified
 
Last edited:
Status
Not open for further replies.
Top