[Trigger] TempPoint variable in every trigger: is it safe?

Status
Not open for further replies.
Level 8
Joined
Jun 1, 2009
Messages
137
A question about TempPoint: is it safe to use a single variable in hundreds of triggers?
Although TempPoint is destroyed ASAP after it was used, in same trigger, with no "Wait" functions, is it possible that another trigger still manages to redirect TempPoint before it was destroyed?
Any known examples of this theoretical issue?
Any limits of TempPoint usage that I should know?
Do I need to create multiple TempPoint variables, or even make a new one for each trigger?
Thanks!
 
Last edited:
A question about TempPoint: is it safe to use a single variable in hundreds of triggers?
Yes.
is it possible that another trigger still manages to redirect TempPoint before it was destroyed?
No.
Any limits of TempPoint usage that I should know?
Not necessarily a limit, but I always leave my TempLocation variable as an array variable due to offset locations and distance between points condition checks.
 
As long as none of the actions the point or group is used for trigger an event it is fine to use a single variable. If they do trigger an event then the currently executing trigger will yield for the event response and that can lead to a sort of race condition with access to the variable which can result in leaks and double destroys.

For this reason local variables are best for this. Sadly GUI lacks this feature.
 
Last edited:
I always leave my TempLocation variable as an array variable due to offset locations and distance between points condition checks.

Yeah, it's quite convenient when you need to operate with multiple points at same time. As I understood, I don't need to make a personal TempPoint or a personal TempPoint Array Index for every new trigger? That's good news!
 
Is it possible that another trigger still manages to redirect TempPoint before it was destroyed?
Any known examples of this theoretical issue?
As long as none of the actions the point or group is used for trigger an event it is file to use a single variable. If they do trigger an event then the currently executing trigger will yield for the event response and that can lead to a sort of race condition with access to the variable which can result in leaks and double destroys.
Here's an example of what DSG described. The TempPoint in the second trigger will be leaked because the first trigger temporarily interrupts the second when the water elemental is created. The TempEffect is still destroyed properly because the variable is not overwritten by the first trigger.

  • Events
    • Unit - A unit enters (Playable map area)
  • Conditions
  • Actions
    • Set TempPoint = Center of Region001 <gen>
    • Unit - Move (Triggering Unit) instantly to TempPoint
    • Custom script: call RemoveLocation(udg_TempPoint)
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to spell
  • Actions
    • Set TempPoint = (Target location of ability being cast)
    • Special Effect - Create an effect at TempPoint using SomeModel.mdx
    • Set TempEffect = (Last created special effect)
    • Unit - Create 1 Water Elemental at TempPoint facing Default building facing degrees
    • Special Effect - Destroy TempEffect
    • Custom script: call RemoveLocation(udg_TempPoint)
 
Well you can use local points for single triggers that does not use loop triggers.

  • X
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Custom script: local location udg_TempLoc
      • Custom script: set udg_TempLoc = GetUnitLoc(GetTriggerUnit())
      • Special Effect - Create a special effect at TempLoc using Abilities\Spells\Other\ANrm\ANrmTarget.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation (udg_TempLoc)
 
Status
Not open for further replies.
Back
Top