WoW:API GetItemGem: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(→‎Common usage: eat section duplicating function signature)
m (Move page script moved page API GetItemGem to API GetItemGem without leaving a redirect)
 
(No difference)

Latest revision as of 04:46, 15 August 2023

WoW API < GetItemGem

Takes an item with a gem in it, and an index from 1-3, and returns the name and link for the gem at that index.

itemName, itemLink = GetItemGem("name"|"itemlink", index) 

Parameters[edit]

Arguments[edit]

(itemName or "itemLink", index)
itemName
String - The Name of the Item, ex: "Hearthstone" (the item must be equiped or in your Inventory for this to work).
"itemLink"
String - The itemLink, when Shift-Clicking items.
index
Number - The index of the desired gem. 1, 2, or 3

Returns[edit]

itemName, itemLink
itemName
String - The name of the gem at the specified index.
itemLink
String - The gem's item Link; you will see the clickable Link instead of the string. (String, such as: "|cff0070dd|Hitem:24033:0:0:0:0:0:0:0|h[Solid Star of Elune]|h|r")

Example[edit]

local itemLink = "|cff0070dd|Hitem:27773:3010:2729:2729:2739:0:0:0|h[Barbaric Legstraps]|h|r"
local gem1name, gem1Link = GetItemGem(itemLink, 1)
local gem2name, gem2Link = GetItemGem(itemLink, 2)
local gem3name, gem3Link = GetItemGem(itemLink, 3)
if gem1name then
  DEFAULT_CHAT_FRAME:AddMessage("Gem 1: "..gem1name..", Link: "..gem1Link)
end
if gem2name then
  DEFAULT_CHAT_FRAME:AddMessage("Gem 2: "..gem2name..", Link: "..gem2Link)
end
if gem3name then
  DEFAULT_CHAT_FRAME:AddMessage("Gem 3: "..gem3name..", Link: "..gem3Link)
end

Result[edit]

As long as Template:Loot, Template:Loot, and Template:Loot all exist in your local cache, you will see the following lines in your chat frame:
Gem 1: Bright Living Ruby, Link: Template:Loot
Gem 2: Bright Living Ruby, Link: Template:Loot
Gem 3: Shifting Nightseye, Link: Template:Loot

Details[edit]

This function will ONLY retrieve data that is in your local cache.
If you have never seen the item that belongs to the Item ID or Item Link it will return nil.
Using the name may be ambiguous if you have more than one of the named item.