WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to handle multiple tooltip (https://www.wowinterface.com/forums/showthread.php?t=59381)

fatrog 11-30-22 07:14 AM

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)

fatrog 12-02-22 08:14 AM

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?

Xrystal 12-02-22 08:31 AM

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.

fatrog 12-02-22 07:23 PM

Thank you for your help

Ok, by using tooltip frame you mean 'GameTooltip' object? It confuses me

Kanegasi 12-02-22 08:19 PM

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)

fatrog 12-08-22 11:14 AM

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)


fatrog 12-10-22 12:37 PM

Ok, i'm stupid. I kept the getItem() method call..

Thanks for help, all good now


All times are GMT -6. The time now is 11:01 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI