Widget API: UIObject:GetName

From AddOn Studio
Jump to navigation Jump to search

Widget API ← UIObject < GetName

Obtains the name of a Widget or other UIObject.

local name = uiobject:GetName()

Parameters[edit]

Returns[edit]

  • name (string) - the name of the UI object, or 'nil' if no name

Summary[edit]

Obtains the name of an object. Great for a lot of uses, like generic object handling functions.

Examples[edit]

Get the name of a default frame
local name = PlayerFrame:GetName()

Result:

name = "PlayerFrame"
Create a frame in Lua with a name
/dump CreateFrame("Frame", "MyFrame"):GetName()

Result:

MyFrame

Details[edit]

Frames and other elements created from XML with a 'name' attribute will set the UIObjects name to the value in the 'name' attribute when they are created, and add a global reference with the same name to the Lua object, like:

<Frame name="PlayerFrame">
  ...
</Frame>

Gets a default global reference:

_G[playerFrame:GetName()] = playerFrame

This is why 'PlayerFrame' in the first example above has the same name as its global variable name, and why so many other default frames follow the same pattern.

Notes[edit]

See also[edit]

  • name - XML name attribute
  • LayoutFrame - XML base frame type with name property