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

[General] SetX/Y for lua language

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
How is this piece of code supposed to look for LUA? If I just remove the "call" like I usually do, trigger breaks.
Removing "call" should be all that's necessary. Maybe temp_unit or temp_X are unset.
  • Custom script: SetUnitX(udg_temp_unit, GetLocationX(udg_temp_X))
Or is temp_X a Real variable? The name implies it might be a Real, in which case you would do this:
  • Custom script: SetUnitX(udg_temp_unit, udg_temp_X)
The SetUnitX() function takes a unit and a real (x coordinate). When you use the GetLocationX() function inside of it you're pulling the X coordinate from the given Point variable. Here is the logic structured in separate lines of code since:
Lua:
local xCoordinate = GetLocationX(udg_temp_point)
SetUnitX(udg_temp_unit, xCoordinate)
The heavy reliance on Points is a GUI limitation and generally unnecessary when writing in code. In fact, almost every function that works with positioning things has a Point version and an X/Y version, it's just that GUI only offers you the Point versions. Relying on the X/Y functions is more efficient and avoids having to deal with the memory leaks involved with creating a new Point object. Also, Points are referred to as Locations and Loc for short when written in code form, I'm not sure why they didn't just stick with one name.

You may already know all of this, but I figured I'd go into detail anyway.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
I have declared it as Real, not as Point. I love how stupid these mistakes can get if you don't pay attention to every detail :D
Thank you for your response but this thread needs to be deleted from the face of the earth so I don't have to live in eternal shame.
Your mistake could help save someone a headache in the future once they discover this thread. Just consider it a public service ;)
 
Top