Widget API: UIObject:GetName

Revision as of 02:38, 13 February 2021 by Bear (talk | contribs) (Created page with "{{widgetmethod}} This function obtains the value of the current XML object. E.g. WorldFrame:GetName() returns "WorldFrame". local name = uiobject:GetName() == Parameters...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Widget API ← UIObject < GetName

Obtains the name of a Widget or other UIObject.

local name = uiobject:GetName()

Parameters

Returns

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

Summary

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

Examples

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

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

See also

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