Em I using variables wrong?

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,823
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:

Wrda

Spell Reviewer
Level 22
Joined
Nov 18, 2012
Messages
1,727
Really depends how you use them, you can have waits and still variables function properly, and yes actions are executed one after another really fast because if it was simultaneously then....it would be stupid and give a lot of crappy errors lol
 
Top