WoW:ItemLink: Difference between revisions
m (Added LUA code to extract the itemString) |
No edit summary |
||
| Line 3: | Line 3: | ||
== itemLink API Type (String) == | == itemLink API Type (String) == | ||
itemLinks are returned by several functions, e.g. [[API GetAuctionItemLink|GetAuctionItemLink]](), [[API GetContainerItemLink | itemLinks are returned by several functions, e.g. [[API GetAuctionItemLink|GetAuctionItemLink]](), [[API GetContainerItemLink|GetContainerItemLink]](), [[API GetInventoryItemLink|GetInventoryItemLink]](), etc. | ||
In essence, they are [[itemString]]s with additional formatting to make in-game text controls display them as clickable hyperlinks. | In essence, they are [[itemString]]s with additional formatting to make in-game text controls display them as clickable hyperlinks. | ||
|cff9d9d9d|Hitem:7073:0:0:0|h[Broken Fang]|h|r | |cff9d9d9d|Hitem:7073:0:0:0:0:0:0:0|h[Broken Fang]|h|r | ||
Broken up in its components: | Broken up in its components: | ||
| Line 15: | Line 15: | ||
** The next three sets of two characters represent the red, green, and blue levels, just like HTML. | ** The next three sets of two characters represent the red, green, and blue levels, just like HTML. | ||
* <tt>"'''|H'''"</tt> – "Hyperlink link data starts here" | * <tt>"'''|H'''"</tt> – "Hyperlink link data starts here" | ||
* <tt>"'''item:7073:0:0:0'''"</tt> – Read more at [[itemString]]. | * <tt>"'''item:7073:0:0:0:0:0:0:0'''"</tt> – Read more at [[itemString]]. | ||
* <tt>"'''|h'''"</tt> – "End of link, text follows" | * <tt>"'''|h'''"</tt> – "End of link, text follows" | ||
* <tt>"'''[Broken Fang]'''"</tt> – The actual text displayed | * <tt>"'''[Broken Fang]'''"</tt> – The actual text displayed | ||
Revision as of 11:13, 31 December 2006
itemLink API Type (String)
itemLinks are returned by several functions, e.g. GetAuctionItemLink(), GetContainerItemLink(), GetInventoryItemLink(), etc.
In essence, they are itemStrings with additional formatting to make in-game text controls display them as clickable hyperlinks.
|cff9d9d9d|Hitem:7073:0:0:0:0:0:0:0|h[Broken Fang]|h|r
Broken up in its components:
- "|cff9d9d9d" – Colorizes the link with a medium grey color (Broken Fang is vendortrash)
- The first two characters after pipe-c may be the alpha level, where
ffis fully opaque. - The next three sets of two characters represent the red, green, and blue levels, just like HTML.
- The first two characters after pipe-c may be the alpha level, where
- "|H" – "Hyperlink link data starts here"
- "item:7073:0:0:0:0:0:0:0" – Read more at itemString.
- "|h" – "End of link, text follows"
- "[Broken Fang]" – The actual text displayed
- "|h" – "End of hyperlink"
- "|r" – Restores color to normal
You can extract the itemString from a given itemLink with the following LUA-code:
local found, _, itemString = string.find(itemLink, "^|%x+|H(.+)|h%[.+%]")
Printing links for debug
Printing out the contents of an item link is perhaps not so obvious; displaying it anywhere in-game will just show you a clickable link. Reformat it slightly to ruin the escape sequences and you'll see what it really looks like:
link = GetContainerItemLink(0, 1); printable = gsub(link, "\124", "\124\124"); ChatFrame1:AddMessage("Here's what it really looks like: \"" .. printable .. "\"");
"124" is the ascii value of the "|" character. If you are writing this in a regular .lua file, feel free to go ahead and just use "|" and "||". However, if you're typing it in an in-game editor, it's better to use the ascii code escape to avoid problems.