Widget API: UIObject:GetName

Revision as of 04:47, 15 August 2023 by Move page script (talk) (Move page script moved page API UIObject GetName to API UIObject GetName without leaving a redirect)
(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