Widget API: UIObject:GetName

Widget API ← UIObject < GetName

Obtains the name of a Widget or other UIObject.

local name = uiobject:GetName()

ParametersEdit

ReturnsEdit

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

SummaryEdit

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

ExamplesEdit

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

DetailsEdit

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.

NotesEdit

See alsoEdit

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