Thread Tools Display Modes
03-20-09, 06:29 AM   #1
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
Obtaining NPC Titles

What is the best way to obtain NPC titles?

Currently I check the second line of the GameTooltip in an OnTooltipSetUnit script, looking if it contains the level information (e.g. Level 80 Humanoid) and if not, I assume it is the NPC title.

This method has some problems when it comes to localisation though. The word "Level" will be different depending on what client is used, so I figured I could make it match TOOLTIP_UNIT_LEVEL which is "Level %s" on enUS. Specifically I matched this, which is "^Level .+":
Code:
"^"..TOOLTIP_UNIT_LEVEL:gsub("%%s",".+")
But the problem is, even this doesn't match on all locals. And as I would really hate adding localisation to my addon(s), does anyone know of an easier way to figure out the NPC title, without depending on localisation?



I have a bonus question when it comes to code like this:
Code:
local _, _, _, _, _, value = SomeFunc();
How does the underscore work in Lua precisely? Does Lua know that underscores shouldn't be set, or does it just make one local variable in this block and set the first five parameters to it? Also, is this code good, or is it better done using select(6,SomeFunc())?

Last edited by Aezay : 03-20-09 at 06:32 AM.
  Reply With Quote
03-20-09, 06:46 AM   #2
Ravendwyr
A Flamescale Wyrmkin
 
Ravendwyr's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2005
Posts: 139
Originally Posted by Aezay View Post
What is the best way to obtain NPC titles?

Currently I check the second line of the GameTooltip in an OnTooltipSetUnit script, looking if it contains the level information (e.g. Level 80 Humanoid) and if not, I assume it is the NPC title.

This method has some problems when it comes to localisation though. The word "Level" will be different depending on what client is used, so I figured I could make it match TOOLTIP_UNIT_LEVEL which is "Level %s" on enUS. Specifically I matched this, which is "^Level .+":
Code:
"^"..TOOLTIP_UNIT_LEVEL:gsub("%%s",".+")
But the problem is, even this doesn't match on all locals. And as I would really hate adding localisation to my addon(s), does anyone know of an easier way to figure out the NPC title, without depending on localisation?
The way CowTip (and probably other tooltip mods) does it is to use a :find pattern as opposed to a :match.

i.e.
Code:
local pattern = "^"..LEVEL -- LEVEL is a global variable and used in all localisations

if string.find(tooltipTextLine2, pattern) then doStuff() -- line two has level data
else doSometingElse() -- line two has guild data
end


Originally Posted by Aezay View Post
I have a bonus question when it comes to code like this:
Code:
local _, _, _, _, _, value = SomeFunc();
How does the underscore work in Lua precisely? Does Lua know that underscores shouldn't be set, or does it just make one local variable in this block and set the first five parameters to it? Also, is this code good, or is it better done using select(6,SomeFunc())?
I don't know how Lua interprets the underscore, as most authors use it when a function returns variables they have no interest in. I think it can be used like other local variables, but it isn't something I've tried.

I myself prefer using underscores instead of select(). Use which one you prefer.
__________________
Twitter | GitHub
  Reply With Quote
03-20-09, 06:49 AM   #3
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by Aezay View Post
I have a bonus question when it comes to code like this:
Code:
local _, _, _, _, _, value = SomeFunc();
How does the underscore work in Lua precisely? Does Lua know that underscores shouldn't be set, or does it just make one local variable in this block and set the first five parameters to it? Also, is this code good, or is it better done using select(6,SomeFunc())?
People just use "_" as a dummy variable, and apparently assigning variables normally is better than select.

Dunno about your other question.
  Reply With Quote
03-20-09, 07:35 AM   #4
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
Thanks for the replies and comments on underscores.

Originally Posted by Ethan Centaurai
The way CowTip (and probably other tooltip mods) does it is to use a :find pattern as opposed to a :match.
find and match does the same really, but match doesn't return the string positions.
I used to use the LEVEL variable, but after getting reports that this wasn't matching the level text from tooltips on the german client, I started to use TOOLTIP_UNIT_LEVEL instead. But now I am told this doesn't match the lines on russian clients.

Couldn't all just use english clients, would make things so much simpler.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Obtaining NPC Titles


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off