• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

A quick question about Variables.

Status
Not open for further replies.
Level 7
Joined
Jun 19, 2017
Messages
141
I have a simple question about the the variable system and how it works in general.
So my question is:
If i use a Variable for example - Point[100] = (Position of Dying Unit) in a trigger that occurs very often during the game, will it be a problem if i use the same Variable of Point[100] with the same value of (Position of Dying Unit) in another trigger. Is there a chance that they will mess up each other?
I'm thinking of this becuase at the end of both triggers i have the custom script that removes the point for leaks. So if both triggers fire at the same time, thus both setting Point[100] = (Position of Dying Unit), but one of them finishes first and removes the point before the other trigger has done his actions, can that happen ?

So basically the question is: Is the point removed globaly(for both triggers) or it get's removed only in the trigger that it was set?
 
Last edited:
Can produce a problem/leak, if the second trigger executes itself by an action done inside the first trigger.
In such a case the Point from the first trigger would leak and be overwritten with the one of the second Trigger, Resulting in only destroying the point of trigger 2.

Example:
  1. Kill/damage Unit in Trigger 1
  2. Event Unit dies in Trigger 2
    1. In such an situation Trigger 1 kills the unit
    2. Trigger 2 interupts Trigger 1 right after the kill/damage action is done, before Trigger 1 is doing anything further.
    3. When the Trigger 2 is finished, Trigger 1 finishes its duty.
You can test this behaviour, if you want by printing out the Trigger names at the end of each trigger.
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
If they have the same events, one will fire first and it will end before the other trigger with the same event fires so it won't mess up the other one. However it's bad practice to do that and can lead you to problems in the future unless you always remember to consider this whenever you use this location (which is much harder especially if you took a break working on the map).
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
I assume the reason you're using the same variable and in an array instead of creating a new variable is you don't want to populate the Variable Manager? You could prefix you naming convention if this is your problem e.g. SPL1_Loc, SPL2_Loc, etc. Or you could move away from GUI so that you can easily use local variables.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
It is impossible for 2 triggers to run at the same time as JASS threads are executed on a single physical thread with a non pre-emptive scheduler.

What can happen is that one thread implicitly yields to execute another. This happens if the thread actions trigger a registered event. This is what Tasyen shows where a trigger thread kills a unit resulting in it having to yield to run all on death event threads before it can resume execution.

The correct solution to this problem is to use a local variable. GUI does not support this feature of JASS. Also be aware that all local declared local handle variables have to have a null reference before the function returns to prevent a handle reference counter leak.
 
Status
Not open for further replies.
Top