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

Are point variables pointers or objects?

Status
Not open for further replies.
Level 4
Joined
Sep 2, 2016
Messages
48
If I do:
Point1 = Position of (Unit1)
Point2 = Position of (Unit2)
Custom script: Destroy Point1
Point1 = Point2
Custom script: Destroy Point2

Will Point1 have the position of Unit2?

If not.
How to do this so it had?
 
Last edited:
Level 15
Joined
Feb 7, 2020
Messages
398
They should be pointers since I think locations are tables.

e.g. in this fiddle:

Lua:
location = {}
location.x = 1
location.y = 2

location2 = {}
location2.x = 100
location2.y = 200

print('before')
print('location1 x = '..location.x)
print('location1 y = '..location.y)
print('location2 x = '..location2.x)
print('location2 y = '..location2.y)

location = location2

print('after')
print('location1 x = '..location.x)
print('location1 y = '..location.y)
print('location2 x = '..location2.x)
print('location2 y = '..location2.y)
Code:
$lua main.lua
before
location1 x = 1
location1 y = 2
location2 x = 100
location2 y = 200
after
location1 x = 100
location1 y = 200
location2 x = 100
location2 y = 200
 
a variable is not the object itself. it only points to it. The object pointed at is destroyed when the destructor function/action for that type is thrown onto a pointer pointing at the object.
Will Point1 have the position of Unit2?
for one action, yes. Point1 and Point2 point both to the same object which is destroyed with the next action. After the destruction, both point now to the same destroyed object.

If you just want that point2 does not point to Unit2 anymore set it to null/nil. This does not destroy the pointed object. One only clears a reference.

Your code looks like it is made with GUI, i think the normal GUI does not provide set point to null, if that is the case and you don't want custom script. You can define a global point which is empy at the beginning and is never set to anything. Then when you want to clear a reference read that global.
 
Status
Not open for further replies.
Top