WoW:API UnitName: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(→Details: Notes on the second return value) |
||
Line 40: | Line 40: | ||
REMOVE the section if you're just going to restate the intro line! --> | REMOVE the section if you're just going to restate the intro line! --> | ||
* UnitName("unit") (or any other unit) will return "Unknown Entity" (Actually the value of the UNKNOWNOBJECT global) if called before the unit in question has been fully loaded into the world. | |||
* The '''realm''' return will be nil even if the player is from a different realm, if it is out of visible range. | |||
* Note that this function always returns two values even though the latter may be nil. The difference is usually moot, but there are some cases where it matters, e.g. <span style="white-space: nowrap;"><tt>tinsert(myTable, UnitName("player"))</tt></span>, which would previously work, but will now cause errors. The fix is to put the expression in parenthesis: <span style="white-space: nowrap;" ><tt>tinsert(myTable, (UnitName("player")) )</tt></span>. | |||
[[Category:World of Warcraft API]] | [[Category:World of Warcraft API]] |
Revision as of 13:03, 28 August 2006
Returns the name and realm of the specified unit.
name, realm = UnitName("unit")
Parameters
Arguments
- ("unit")
- unit
- String - The UnitId to query (e.g. "player", "party2", "pet", "target" etc.)
Returns
- name
- String - The name of the specified unit.
- realm
- String - The realm the specified unit is from. If from your own realm, then realm == nil (but the 2nd return value is still there). This is as of 1.12
Example
local playerName = UnitName("player"); ChatFrame1:AddMessage('Hi my name is: ' .. playerName);
Result
- Prints the player's name to the chat frame. e.g.
Hi my name is: Octon
Details
- UnitName("unit") (or any other unit) will return "Unknown Entity" (Actually the value of the UNKNOWNOBJECT global) if called before the unit in question has been fully loaded into the world.
- The realm return will be nil even if the player is from a different realm, if it is out of visible range.
- Note that this function always returns two values even though the latter may be nil. The difference is usually moot, but there are some cases where it matters, e.g. tinsert(myTable, UnitName("player")), which would previously work, but will now cause errors. The fix is to put the expression in parenthesis: tinsert(myTable, (UnitName("player")) ).