• 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.

[Trigger] Question about Point Leaks

Status
Not open for further replies.
Level 30
Joined
Jul 23, 2009
Messages
1,033
I realized one thing that puzzled me.

When I create a point, and let's say I set it to Point1, and then have a trigger to use that point for another trigger and I set Point2=Point1 - Now if I have a trigger in which I destroy Point2 I have realized that I also destroy Point1 since they are the same point but with different references. This means all the references I still wanted to have to Point1 are lost.

So the question is; If I want to keep using Point1 but no longer need the Point2 reference, can I just skip destroying Point2? Because it shouldn't leak as it doesn't create its' own point but instead it gets linked to Point1? Is this correct or am I mistaken?
 
Level 7
Joined
Mar 6, 2006
Messages
282
Well I gotta ask, why set Point2 to Point1 if they're the same point?

And yes, you appear to be correct, I just tested. If I'm wrong, then you can always do this:

  • Set Point2 = (Point ( (X of Point1), (Y of Point1) ) )
That's 'Conversion - Convert Coords to Point'

Then you have two separate points that have the same X and Y and both need to be destroyed separately.
 
Level 30
Joined
Jul 23, 2009
Messages
1,033
Well I gotta ask, why even set Point2 to Point1 if they're the same point?

And yes, you appear to be correct, I just tested. If I'm wrong, then you can always do this:

  • set Point2 = Point( X of Point1, Y of Point2 )
That's 'Conversion - Convert Coords to Point'

Then you have two separate points that have the same X and Y and both need to be destroyed separately.

Well the reason is just to make it more simple for me to make the triggers. The case is; I use dynamic indexing to save every neutral hostile unit's spawn location so in triggers the spawn point is set as Point1[Unit_Index] and then I use another system to track neutral hostiles in combat and there the point is temporarily saved as Point2[CombatUnit_Index], I don't know how to explain it better :p But thanks for the reply!
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
that is because variables are pointers. They point at the location/unit/etc.
It is not only for points... I think everything that has handle will behave that way.

If you no longer want Point2 to use the same location as Point1, you can just null it.
  • Custom script: set udg_Point2 = null
My understanding of this is the following:
Code:
Variable -----points at------> handle (e.g. location, unit, ...)

then using calls to destroy the handle (like call RemoveLocation), then it will do this:
Variable -----points at------> NULL

but if you null the variable (e.g. set udg_loc = null), it will do this:
Variable ____________  handle

as you can see, variable no longer points at the handle, but the handle remains
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
As I understand it, his problem/surprise was this:

First, he had something like this:

  • Trigger 1
  • Set Loc1 = *somewhere*
  • *actions involving Loc1*
  • Trigger 2
  • Set Loc2 = Loc1
  • *actions involving Loc2*
  • Custom script: call RemoveLocation(udg_Loc2)
And then, after Trigger 2 ran, he wanted to use Loc1 again and was surprised that by removing location Loc2, he also removed Loc1 that way.
 
@TO
As said above all variables are pointers. They point to object in memory ( like a location / units / whatever else)
What that means is lets say point 1 is pointing to a location in your map. Then you set point 2 = point 1.
That means that now point 2 points to the location that point 1 refers to. So if you destroy the location, you destroy the memory used to keep that location in game. Now point 1 and point 2 refer to a null / empty reference in memory.
If you want to make point 2 not equal to point 1 after you use point to simply set point 2 = null. ( you need custom script for this.)
 
Status
Not open for further replies.
Top