Thread Tools Display Modes
03-23-11, 07:21 PM   #1
Crissa
A Flamescale Wyrmkin
 
Crissa's Avatar
Join Date: May 2008
Posts: 136
GetParent() vs parent:

I can't find this in general LUA information, probably because it's splattered all over code samples and I guess is something fairly simple.

What's the difference between GetParent().part and parentart?

-Crissa
  Reply With Quote
03-23-11, 08:51 PM   #2
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
f:GetParent().part
f.parent.part

the difference between the 2, is that you can only use the second one, if you previously did:

f.parent = f:GetParent()

makes sense?
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
03-24-11, 04:34 PM   #3
Crissa
A Flamescale Wyrmkin
 
Crissa's Avatar
Join Date: May 2008
Posts: 136
Sure! I was wondering if that was the case.

In debugging, is there any way to display an object's name, so I'm not poking around blindly when trying to work on something that is a child of a parent of a child of a... I forgot what loop I'm in? My IDE doesn't do class traces. (it doesn't do much of anything, really ^-^)

-Crissa
  Reply With Quote
03-24-11, 07:28 PM   #4
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
You can do

print(f)

where f is a table/frame, and Lua will print the memory address of that table/frame. If the frame was created with a global name, then

f = CreateFrame("Frame", UIParent, "Hello")
print(f:GetName()) -- will print "Hello"

will work, or it will print "nil" if the name was left out.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
03-24-11, 08:49 PM   #5
Crissa
A Flamescale Wyrmkin
 
Crissa's Avatar
Join Date: May 2008
Posts: 136
Yeah, but I can't write Hello:GetName(), right? Because while that's the name, that's not the class name... Or is it?

-Crissa
  Reply With Quote
03-24-11, 10:40 PM   #6
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
Originally Posted by Crissa View Post
Yeah, but I can't write Hello:GetName(), right? Because while that's the name, that's not the class name... Or is it?

-Crissa
Technically you can, because Hello would be a global variable. The 3rd argument to CreateFrame is the global name to be given to the frame, and GetName() returns the same string.

Global variables can be accessed directly, or in the _G table, so

Hello:GetName()
_G["Hello"]:GetName()
_G.Hello:GetName()

would all accomplish the same thing, which is to return the string "Hello".

There are no "classes" in Lua, but you can attach tables with metatables to mimic class-like behavior (all frames have a frame metatable, which defines the functions like GetName()).
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » GetParent() vs parent:


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