Thread Tools Display Modes
04/14/14, 11:23 AM   #1
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
GetAnchor() ?

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 ?

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 - I guess the operator tests if the method exists ??? - but then why can we use MyElement:SetAnchor(args) ?

Well then I tried

Code:
MyElement.GetAnchor()
But I get API error 'userdata expected, got no value'.

Doc says you have to pass the AnchorIndex to the function so I finally tried

Code:
MXPVUI.GetAnchor(MXPVUI.anchorIndex)
No luck

Where do I put the AnchorIndex tag in the XML file ? Am I doing the thing right ???

Explanation very welcome if you experienced doing the same thing
  Reply With Quote
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
04/14/14, 02:34 PM   #3
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Thumbs up

Wow I seems I totally overlooked the return values of GetAnchor dunno why

Well thank you for the explanation.

Any idea what the 'index' param refers to

Is it something I am supposed to define in the XML file ?

Thx.
  Reply With Quote
04/14/14, 02:41 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
There can be more than one anchor set.
  Reply With Quote
04/14/14, 02:49 PM   #5
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
You can have more than one anchor defined. This comes in handy on images and dynamic window sizing to have two anchor points. The index is not param is not a attribute in the XML version but the index order of creation.

Code:
<Texture name="$(parent)TopDivider" textureFile="EsoUI/Art/Miscellaneous/horizontalDivider.dds">
	<Dimensions y="4"/>
	<Anchor point="TOPLEFT" offsetX="-80" offsetY="25" />
	<Anchor point="TOPRIGHT" offsetX="80" offsetY="25" />
</Texture>
--halja
  Reply With Quote
04/14/14, 02:53 PM   #6
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Thumbs up Iyanga

Just tried your example and it worked perfectly !

I didn't know at all about this way of instancing a function's return values.

I honestly thought var = MyElement:GetAnchor(MyElement.anchorIndex) would instance a table/array into 'var' that you could access via offsetx = var.offsetX

Looks like I was wrong

So - another thumbs up and and hats down for you

Last edited by Edda : 04/14/14 at 02:57 PM.
  Reply With Quote
04/14/14, 03:39 PM   #7
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Originally Posted by Halja View Post
You can have more than one anchor defined. This comes in handy on images and dynamic window sizing to have two anchor points. The index is not param is not a attribute in the XML version but the index order of creation.
I tried MAIN:GetAnchor(1) but it seems I don't get the correct anchor. The anchor I want to get is the very first in my XML file -> the anchor from my main element. This element only has 1 anchor (not counting childs) but something looks wrong.
  Reply With Quote
04/14/14, 04:16 PM   #8
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Hmm it seems I had a conflict from creating an Anchor in my XML file and creating another via :SetAnchor.

Anyways the only way I could actually get my anchor (after deleting it in the XML file) is with :GetAnchor()

:GetAnchor(1) doesn't work (wrong reference)

:GetAnchor(0) doesn't work either.

Any idea ? I made the thing working tho but just trying to figure out the problem

thx
  Reply With Quote
04/14/14, 05:34 PM   #9
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
Originally Posted by Edda View Post
Just tried your example and it worked perfectly !

I didn't know at all about this way of instancing a function's return values.

I honestly thought var = MyElement:GetAnchor(MyElement.anchorIndex) would instance a table/array into 'var' that you could access via offsetx = var.offsetX

Looks like I was wrong

So - another thumbs up and and hats down for you
In lua you are doing the kind of the opposite. You are taking an array return and unpacking it to the individual variables to access. If you don't catch them all, they are just tossed away. That is why you only had the first return value on the initial attempt to use it.

I'll have to look at your index question when I get home. I thought is was an integer reference.
  Reply With Quote
04/15/14, 02:30 AM   #10
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Okay thanks. It seems MAIN:GetAnchor() (without args) gets the correct (first) anchor BUT, when I am actually moving my UI element around, the anchor reference (BOTTOMRIGHT) get's srewed and changes to the closest sreen corner anchor point.

So if I move my element close to TOPLEFT, then the anchor point changes to TOPLEFT even tho I initially created the anchor with a BOTTOMRIGHT reference.

So I had to save the anchor reference too in user's variables to make the thing working.
  Reply With Quote
04/15/14, 06:55 AM   #11
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
Yea I'm seeing that too. It looks like to me for muilt-anchored controls a ClearAnchors() call first is the way to go. You could MyElement:ClearAnchors() and then do the two set anchors.
--halja
  Reply With Quote
04/15/14, 07:19 AM   #12
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Generally speaking, whenever I was developing addons with dynamic UI elements for WoW, I found I always needed to issue a ClearAnchors() command before using SetAnchor().

I recall trying all sorts of stuff to change the anchor and it either failed miserable or just wasn't reliable for a variety of reasons.
  Reply With Quote
04/15/14, 10:38 AM   #13
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
All right thanks I might try that.
  Reply With Quote
04/15/14, 01:15 PM   #14
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Edda View Post
Okay thanks. It seems MAIN:GetAnchor() (without args) gets the correct (first) anchor BUT, when I am actually moving my UI element around, the anchor reference (BOTTOMRIGHT) get's srewed and changes to the closest sreen corner anchor point.
The documentation for SetAnchor would have warned you.
  Reply With Quote
04/15/14, 02:44 PM   #15
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Originally Posted by Iyanga View Post
The documentation for SetAnchor would have warned you.
Haha, nice wiki update. I love the pictures.
  Reply With Quote
04/17/14, 04:11 AM   #16
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Stormknight View Post
Haha, nice wiki update. I love the pictures.
Thanks.

When I had to use the function, I had a total brain fart and just couldn't imagine what the point of two AnchorPositions is. And once it hit me, I had the urge to visualize it
  Reply With Quote
04/17/14, 12:44 PM   #17
bsrealm
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 7
ClearAnchor! I discovered we have to use that after an hour of debugging today! Thanks for posting on the wiki.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » GetAnchor() ?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off