Thread Tools Display Modes
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
12-02-22, 08:14 AM   #2
fatrog
A Fallenroot Satyr
Join Date: Nov 2022
Posts: 21
noone knows?

I wanted to add that it also appens (obviously) on comparison tooltip (shift key)

Edit:
Ultimately, is there a way to make errors die silently in lua?

Last edited by fatrog : 12-02-22 at 08:28 AM.
  Reply With Quote
12-02-22, 08:31 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,927
It looks like it is referring to the line

_, ItemLink = tt:GetItem()

Which is in the function mentioned by the line you first posted.

It looks like this is one of the functions removed, or being removed based on the dev comments in GameTooltip.lua.

Lua Code:
  1. -- Temp replacements for GetX API that's been removed
  2. -- TODO: Evaluate for removal
  3. function GameTooltipDataMixin:GetItem()
  4.     return TooltipUtil.GetDisplayedItem(self);
  5. end
https://www.townlong-yak.com/framexm...ooltip.lua#983

Try using the TooltipUtil route and using your tooltip frame instead of self.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
12-02-22, 07:23 PM   #4
fatrog
A Fallenroot Satyr
Join Date: Nov 2022
Posts: 21
Thank you for your help

Ok, by using tooltip frame you mean 'GameTooltip' object? It confuses me
  Reply With Quote
12-02-22, 08:19 PM   #5
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Within your code at that GetItem spot, tt is a tooltip frame. When you register GetItemGCDInfos at the bottom, the UI is feeding your function the current tooltip frame being rendered, which is usually GameTooltip.

Replace

tt:GetItem()

with

TooltipUtil.GetDisplayedItem(tt)
  Reply With Quote
12-08-22, 11:14 AM   #6
fatrog
A Fallenroot Satyr
Join Date: Nov 2022
Posts: 21
Hello,

Thank you so much for explainations. And sorry for very late answer.

So, as you suggested, I have made it like this:

Lua Code:
  1. local function GetItemGCDInfos(tt)
  2.     ctt = TooltipUtil.GetDisplayedItem(tt)
  3.     gcdMS, cooldownMS, spellID, ItemLink = nil
  4.    
  5.     if ctt ~= nil then
  6.         _, ItemLink = ctt:GetItem()
  7.         _, spellID = GetItemSpell(ItemLink)
  8.     end
  9.    
  10.     if spellID ~= nil then
  11.         cooldownMS, gcdMS = GetSpellBaseCooldown(spellID)
  12.     end
  13.    
  14.     if gcdMS ~= nil then
  15.         SetNewLineWithGCD(ctt,gcdMS)
  16.     end
  17. end

Unfortunatly, I still got the same error (eg. when I get multiple tooltip like when I put my cursor over the suggested items in the "edit stuff" menu)

  Reply With Quote
12-10-22, 12:37 PM   #7
fatrog
A Fallenroot Satyr
Join Date: Nov 2022
Posts: 21
Ok, i'm stupid. I kept the getItem() method call..

Thanks for help, all good now
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to handle multiple tooltip

Thread Tools
Display Modes

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