Thread: GetAnchor() ?
View Single Post
04/14/14, 12:23 PM   #2
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Edda View Post
Hello,

I am facing a little problem here : I am new to Lua and don't konw the difference between the '.' operator and ':' operators.

I know the dot operator is used to get/use parameters and methods of said object but why and when do we have to use the ':' operator ?
obj.myfunc(obj, param1)
equals
obj:myfunc(param1)

It's just there to save you the hassle to enter the instance of an object as first parameter, if the function expects an instance of the object as first parameter.

My second question is : I am trying to save an UI element position is user's saved variables but I haven't had luck with 'GetAnchor()' yet. I did try

Code:
MyElement:GetAnchor()
returns boolean (true) only
The documentation for GetAnchor states that it returns multiple values:

bool isValidAnchor, integer point, object relativeTo, integer relativePoint, number offsetX, number offsetY

If you only check one value, it equals the first value.

The correct way to call it would be
local isValidAnchor, point, relativeTo, relativePoint, offsetX, offsetY = MyElement:GetAnchor(index)
OR
local isValidAnchor, point, relativeTo, relativePoint, offsetX, offsetY = MyElement.GetAnchor(MyElement, index)

Then you have all the values in the different variables.
  Reply With Quote