WoW:API UnitName: Difference between revisions

m
Move page script moved page API UnitName to WoW:API UnitName without leaving a redirect
(→‎Details: Notes on the second return value)
m (Move page script moved page API UnitName to WoW:API UnitName without leaving a redirect)
 
(7 intermediate revisions by 7 users not shown)
Line 7: Line 7:
<!-- List return values and arguments as well as function name, follow Blizzard usage convention for args -->
<!-- List return values and arguments as well as function name, follow Blizzard usage convention for args -->
  name, realm = UnitName("unit")
  name, realm = UnitName("unit")


== Parameters ==
== Parameters ==
Line 18: Line 17:
=== Returns ===
=== Returns ===
<!-- List each return value, together with its type -->
<!-- List each return value, together with its type -->
:;name : String - The name of the specified unit.
:;name
:;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
:: String - The name of the specified unit, "nil" if not applicable (e.g., if the specified unit is "target" but the player has no target selected).
:;realm
:: String - The realm the specified unit is from. For "player" returns nil, for any other character on your own realm returns an empty string. This is as of 1.12


== Example ==
== Example ==
Line 44: Line 45:


* The '''realm''' return will be nil even if the player is from a different realm, if it is out of visible range.
* The '''realm''' return will be nil even if the player is from a different realm, if it is out of visible range.
 
* Realm name will not include server type


* 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>.
* 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>.


* The default Blizzard UI defines [[API_GetUnitName|GetUnitName]](unit, showServerName) which only returns the unit name, but for characters from another server appends the server name (showServerName==true) or "(*)" (if showServerName==false).
[[Category:World of Warcraft API]]
[[Category:World of Warcraft API]]
Anonymous user