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

[Solved] Several point variables with same location. Removal question.

Status
Not open for further replies.
Great title!
Quick question about points saved in variables.

Set Temp_Point_1 = some location
Set Temp_Point_2 = Temp_Point_1
call RemoveLocation (udg_Temp_Point_2)

I assume this will also remove Temp_Point_1 because they are the same point, right?

Set Temp_Point_1 = some location
Set Temp_Point_2 = same location as above
call RemoveLocation (udg_Temp_Point_2)

However. Will this also remove Temp_Point_1?
The two variables are set to the exact location but they are not equal to each other. Or will they automatically be the same point because they are set to the same point in the map?
 
Last edited by a moderator:
Yeah.
  • Set Point1 = Point2
this doesn't make the variables equal as objects, it makes their values equal (the information they contain). Removing %1 or %2 won't remove the other.
Incorrect.

According to your logic (which is understandable, don't get me wrong), this:
  • Set TimeCount1 = 5
  • Set TimeCount2 = TimeCount1
  • Set TimeCount1 = 19
will eventually cause TimeCount2 to also become 19. But it won't, because you make changes exclusively to %1.
 
Level 5
Joined
May 6, 2013
Messages
125
In the first example, Temp_Point1 and Temp_Point2 both contain a handle to the same location, so removing this location will invalidate both variables.

In the second example, you (most likely) created to seperate locations, which, while having the same values, are seperate objects with different handle values. Removing one of them will not touch the other one.
 
Actually, you should question me. Imp Midna is totally right. I just ran a few tests and the locations are indeed removed. Weirdly enough, this doesn't happen with reals. I guess because they are not considered objects. This still applies to your first question, in the second they will remain intact.

After so much time, I learned something new. Thanks for the motive :D
 
Level 5
Joined
May 6, 2013
Messages
125
Its essential to understand the concept of pointers and handles for this topic. The Variables do not contain the actual objects, but just the handles to it. By copying Temp_Point1 into Temp_Point2, you do not copy the object, you copy the handle, resulting in both variables, while being different variables, pointing to the same objects.
When you remove a location, the function takes the handle, and removes the location object that the handle refers to. It doesn't matter which variable you use to remove the location, because both variables refer to the same location object, and of course, therefor, removing the location will invalidate both objects. It's not that the operation has any influence on the variables Temp_Point1 and Temp_Point2 itself. Both of them still contain the handle. But the Point that the handle once refered to is now gone.

A good way to memorize this is to think of unit variables. If writing Temp_Unit1 = Temp_Unit2 would create a copy of this unit, a second unit would have to pop up somwhere on your field. But of course, it doesn't, all you do is copy the handle.
 
Its essential to understand the concept of pointers and handles for this topic. The Variables do not contain the actual objects, but just the handles to it. By copying Temp_Point1 into Temp_Point2, you do not copy the object, you copy the handle, resulting in both variables, while being different variables, pointing to the same objects.
When you remove a location, the function takes the handle, and removes the location object that the handle refers to. It doesn't matter which variable you use to remove the location, because both variables refer to the same location object, and of course, therefor, removing the location will invalidate both objects. It's not that the operation has any influence on the variables Temp_Point1 and Temp_Point2 itself. Both of them still contain the handle. But the Point that the handle once refered to is now gone.

That was what I thought hence the phrasing in my first example.
I was just a little unclear on the latter example :)

Your answers, both of you, helped me cement that my own thoughts were correct. Thank you :)
 
Copy by value versus copy by reference. Handles are copied by reference, non-handles are copied by value. It gets fuzzy with strings though because of internalizing and the string table.
JASS:
function CaseA takes nothing returns nothing
    local location PointA=Location(100,100)
    local location PointB=PointA
    call RemoveLocation(PointB)
    call BJDebugMsg("Location: "+R2S(GetLocationX(PointA))+", "+R2S(GetLocationY(PointA))+".") // Should print 0,0.
endfunction

function CaseB takes nothing returns nothing
    local location PointA=Location(100,100)
    local location PointB=Location(100,100)
    call RemoveLocation(PointB)
    call BJDebugMsg("Location: "+R2S(GetLocationX(PointA))+", "+R2S(GetLocationY(PointA))+".") // Will print 100,100.
endfunction
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Set Temp_Point_1 = some location
Set Temp_Point_2 = Temp_Point_1
call RemoveLocation (udg_Temp_Point_2)
Both Temp_Point_1 and Temp_Point_2 point at the some location object at time of removal. Thus both of them will become a de-registered handle. The location will be destroyed but the handle cannot be recycled until both variables are assigned a different value (null or another location).

Set Temp_Point_1 = some location
Set Temp_Point_2 = same location as above
call RemoveLocation (udg_Temp_Point_2)
Depends entirely on the operation og "some location". If it returns a constant then after this is run it will return null and the same case as above applies (both variables point to invalid handle and will prevent handle recycling until changed to another value).

If it returns a new location object with each call of "some location" then Temp_Point_1 will still hold a valid living location object while Temp_Point_2 will hold a broken handle (as above, it will need to be assigned a different value for the handle index to be recycled).
 
Status
Not open for further replies.
Top