Thread Tools Display Modes
01/13/16, 02:03 AM   #1
vandel212
Join Date: Jan 2016
Posts: 17
Getting an item's color

Hi, I looked on the wiki API, and did search on the forums here, and didn't find anything. If I have an Item Link, is there a way I can get it's color (White, green, blue etc...)?

Thank you.
  Reply With Quote
01/13/16, 02:10 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by vandel212 View Post
Hi, I looked on the wiki API, and did search on the forums here, and didn't find anything. If I have an Item Link, is there a way I can get it's color (White, green, blue etc...)?

Thank you.
Jo
Lua Code:
  1. local qualityText = "Text you want to colorize"
  2. local quality = GetItemLinkQuality(itemLink)
  3. qualityText = GetItemQualityColor(quality):Colorize(qualityText)
  Reply With Quote
01/13/16, 02:20 AM   #3
vandel212
Join Date: Jan 2016
Posts: 17
Originally Posted by votan View Post
Jo
Lua Code:
  1. local qualityText = "Text you want to colorize"
  2. local quality = GetItemLinkQuality(itemLink)
  3. qualityText = GetItemQualityColor(quality):Colorize(qualityText)
Thank you for the very quick response! Will this return the name of the color? And by that I mean will it say "Green"? Or will it just make the text green? Because I actually need the name of the color.
  Reply With Quote
01/13/16, 02:24 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by vandel212 View Post
Thank you for the very quick response! Will this return the name of the color? And by that I mean will it say "Green"? Or will it just make the text green? Because I actually need the name of the color.
Yes, using the same "quality" value:
Lua Code:
  1. local qualityText = GetString("SI_ITEMQUALITY", quality)
It returns the localized name of the quality.
Or do you really mean the color name?

/edit: I did not found strings defining "green" or "blue", etc. So I think you have to create your own strings.

Last edited by votan : 01/13/16 at 02:42 AM.
  Reply With Quote
01/13/16, 06:07 AM   #5
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Lua Code:
  1. local qualityNames = {}
  2.     for i = 0, 5 do
  3.         local color = GetItemQualityColor(i)
  4.         local qualName = color:Colorize(GetString("SI_ITEMQUALITY", i))
  5.         qualityNames[i] = qualName
  6.     end

Last edited by Ayantir : 01/13/16 at 06:09 AM.
  Reply With Quote
01/19/16, 11:19 PM   #6
vandel212
Join Date: Jan 2016
Posts: 17
Originally Posted by votan View Post
Yes, using the same "quality" value:
Lua Code:
  1. local qualityText = GetString("SI_ITEMQUALITY", quality)
It returns the localized name of the quality.
Or do you really mean the color name?

/edit: I did not found strings defining "green" or "blue", etc. So I think you have to create your own strings.
So close! It doesn't return a color, which isn't a problem as I could just relate words to colors, but it's not full proof. For example, White Text items will return a value of "worn", but Green Text items return "worn" as well, so I have no way of knowing the actual color since "worn" could be 2 or more colors.
  Reply With Quote
01/20/16, 12:06 AM   #7
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by vandel212 View Post
So close! It doesn't return a color, which isn't a problem as I could just relate words to colors, but it's not full proof. For example, White Text items will return a value of "worn", but Green Text items return "worn" as well, so I have no way of knowing the actual color since "worn" could be 2 or more colors.
Are you sure? Show us some code.

If it's "green" and returns an item-quality of 0=worn, it can not be "green".
There may some exceptions for items which do not exist in different qualities: Fishes and trophys have only one assigned quality: "Blue" fishes are always "blue".
  Reply With Quote
01/20/16, 02:40 AM   #8
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by vandel212 View Post
So close! It doesn't return a color, which isn't a problem as I could just relate words to colors, but it's not full proof. For example, White Text items will return a value of "worn", but Green Text items return "worn" as well, so I have no way of knowing the actual color since "worn" could be 2 or more colors.
Definitely a typo in your code. You're giving an uninitialized/non-number second argument to GetString("SI_ITEMQUALITY", quality), and it then returns what it would for the default (0).
  Reply With Quote
01/20/16, 03:12 AM   #9
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by merlight View Post
Definitely a typo in your code. You're giving an uninitialized/non-number second argument to GetString("SI_ITEMQUALITY", quality), and it then returns what it would for the default (0).
I was talking about the quality variable of the previous code example.
here is the complete code:
Lua Code:
  1. local function QualityNameFromItemLink(itemLink)
  2.   local quality = GetItemLinkQuality(itemLink)
  3.   local qualityText = GetString("SI_ITEMQUALITY", quality)
  4.   return qualityText
  5. end
  Reply With Quote
01/21/16, 01:45 AM   #10
vandel212
Join Date: Jan 2016
Posts: 17
Originally Posted by votan View Post
I was talking about the quality variable of the previous code example.
here is the complete code:
Lua Code:
  1. local function QualityNameFromItemLink(itemLink)
  2.   local quality = GetItemLinkQuality(itemLink)
  3.   local qualityText = GetString("SI_ITEMQUALITY", quality)
  4.   return qualityText
  5. end
Yep, I messed up! I must have had the same variable showing up in the loop. Now Worn items are grey, and Fine items are Green. Thanks for the help, this'll add a nice bit of pazaz to the project.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Getting an item's color


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