Hello,
I have a problem with my tiny addon I made. I get error while its event get triggered by multiple tooltip at once.
eg. when you put your mouse on inventory items while switch it and it show other options
This is my event handler so far:
Code:
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, GetItemGCDInfos)
The error is:
Code:
attempt to call method 'GetItem' (a nil value)
it is refering at the function I use to get spell gcd from items. It works for the "main" tooltip, but throw the error for the other ones
And this is my whole code for the sake of this post:
Lua Code:
local gcdMS, gcdMSControl, cooldownMS, displayedName, spellID, ItemName, ItemLink, gcdText
local function MSround(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
local function SetNewLineWithGCD(tt,gcdMS)
gcdMS = MSround(gcdMS / 1000,2)
gcdText = ""
gcdText = "GCD "..gcdMS.."sec"
tt:AddLine(" ",1,1,1)
tt:AddLine(gcdText,0,1,0)
end
local function GetSpellGCDInfos(tt)
gcdMS, cooldownMS, spellID = nil
_, spellID = tt:GetSpell()
if spellID ~= nil then
cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
end
if gcdMS ~= nil then
SetNewLineWithGCD(tt,gcdMS)
end
end
local function GetItemGCDInfos(tt)
gcdMS, cooldownMS, spellID, ItemLink = nil
_, ItemLink = tt:GetItem()
_, spellID = GetItemSpell(ItemLink)
if spellID ~= nil then
cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
end
if gcdMS ~= nil then
SetNewLineWithGCD(tt,gcdMS)
end
end
local function GetMacroGCDInfos(tt)
gcdMS, cooldownMS, displayedName, spellID, itemName, ItemLink = nil
displayedName = _G[tt:GetName().."TextLeft"..1]:GetText()
_,_,_,_,_,_,spellID = GetSpellInfo(displayedName)
if spellID ~= nil then
cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
else
_,ItemLink = GetItemInfo(displayedName)
_, spellID = GetItemSpell(ItemLink)
if spellID ~= nil then
cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
end
end
if gcdMS ~= nil then
SetNewLineWithGCD(tt,gcdMS)
end
end
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Spell, GetSpellGCDInfos)
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, GetItemGCDInfos)
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Macro, GetMacroGCDInfos)