View Single Post
11-30-22, 07:14 AM   #1
fatrog
A Fallenroot Satyr
Join Date: Nov 2022
Posts: 21
How to handle multiple tooltip

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:
  1. local gcdMS, gcdMSControl, cooldownMS, displayedName, spellID, ItemName, ItemLink, gcdText
  2.  
  3. local function MSround(num, numDecimalPlaces)
  4.   local mult = 10^(numDecimalPlaces or 0)
  5.   return math.floor(num * mult + 0.5) / mult
  6. end
  7.  
  8. local function SetNewLineWithGCD(tt,gcdMS)
  9.         gcdMS = MSround(gcdMS / 1000,2)
  10.         gcdText = ""
  11.         gcdText = "GCD "..gcdMS.."sec"
  12.         tt:AddLine(" ",1,1,1)
  13.         tt:AddLine(gcdText,0,1,0)
  14. end
  15.  
  16. local function GetSpellGCDInfos(tt)
  17.     gcdMS, cooldownMS, spellID = nil
  18.    
  19.     _, spellID = tt:GetSpell()
  20.     if spellID ~= nil then
  21.         cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
  22.     end
  23.  
  24.     if gcdMS ~= nil then
  25.         SetNewLineWithGCD(tt,gcdMS)
  26.     end
  27. end
  28.  
  29. local function GetItemGCDInfos(tt)
  30.     gcdMS, cooldownMS, spellID, ItemLink = nil
  31.    
  32.     _, ItemLink = tt:GetItem()
  33.     _, spellID = GetItemSpell(ItemLink)
  34.    
  35.     if spellID ~= nil then
  36.         cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
  37.     end
  38.    
  39.     if gcdMS ~= nil then
  40.         SetNewLineWithGCD(tt,gcdMS)
  41.     end
  42. end
  43.  
  44. local function GetMacroGCDInfos(tt)
  45.     gcdMS, cooldownMS, displayedName, spellID, itemName, ItemLink = nil
  46.    
  47.     displayedName = _G[tt:GetName().."TextLeft"..1]:GetText()
  48.     _,_,_,_,_,_,spellID = GetSpellInfo(displayedName)
  49.    
  50.     if spellID ~= nil then
  51.         cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
  52.     else
  53.         _,ItemLink = GetItemInfo(displayedName)
  54.         _, spellID = GetItemSpell(ItemLink)
  55.         if spellID ~= nil then
  56.             cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
  57.         end
  58.     end
  59.    
  60.     if gcdMS ~= nil then
  61.         SetNewLineWithGCD(tt,gcdMS)
  62.     end
  63. end
  64.  
  65. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Spell, GetSpellGCDInfos)
  66. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, GetItemGCDInfos)
  67. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Macro, GetMacroGCDInfos)
  Reply With Quote