WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Why OnTooltipSetUnit callback is not working? (https://www.wowinterface.com/forums/showthread.php?t=59198)

nyxxir 08-22-22 07:48 AM

Why OnTooltipSetUnit callback is not working?
 
Lua Code:
  1. GameTooltip:HookScript("OnTooltipSetUnit", TooltipCallback)
  2.  
  3. function TooltipCallback(tooltip, ...)
  4.     local unitName, unitId = tooltip:GetUnit()
  5.     GameTooltip:AddLine(unitName)
  6. end

The new line is not added. What is wrong? And what arguments OnTooltipSetUnit callback should have? I've a lot of different options ('self', 'self, tooltip', 'self, ...', 'tooltip, ...' and so on)...

Kanegasi 08-22-22 02:25 PM

You can name the arguments whatever you want. The first one provided here will be the tooltip frame and you can skip the vararg (...).

As for the line not working, you need to use :Show() for custom lines to render. You should also use the tooltip frame object you already have, not GameTooltip.

Finally, you should put the hook after defining the function. TooltipCallback does not exist where you are using it. You weren't getting an error since nil is a valid argument to HookScript.

Lua Code:
  1. function TooltipCallback(tooltip)
  2.     local unitName, unitId = tooltip:GetUnit()
  3.     tooltip:AddLine(unitName)
  4.     tooltip:Show()
  5. end
  6.  
  7. GameTooltip:HookScript("OnTooltipSetUnit", TooltipCallback)

nyxxir 08-23-22 07:20 AM

Quote:

Originally Posted by Kanegasi (Post 340906)
You can name the arguments whatever you want. The first one provided here will be the tooltip frame and you can skip the vararg (...).

As for the line not working, you need to use :Show() for custom lines to render. You should also use the tooltip frame object you already have, not GameTooltip.

Finally, you should put the hook after defining the function. TooltipCallback does not exist where you are using it. You weren't getting an error since nil is a valid argument to HookScript.

Lua Code:
  1. function TooltipCallback(tooltip)
  2.     local unitName, unitId = tooltip:GetUnit()
  3.     tooltip:AddLine(unitName)
  4.     tooltip:Show()
  5. end
  6.  
  7. GameTooltip:HookScript("OnTooltipSetUnit", TooltipCallback)

Thank you!
Anyway, my addon is not working... How do you debug addons? Because I even don't know where is the problem.

Fizzlemizz 08-23-22 07:43 AM

BugGrabber and BugSack work together for debugging addons.

SDPhantom 08-23-22 02:59 PM

As Fizzlemizz pointed out, those are great addons for enhancing error reporting.

These expand on Blizzard's own error system that depends on the scriptErrors CVar.
This is disabled by default and should be turned on if you're working on code.
Code:

/console scriptErrors 1


All times are GMT -6. The time now is 05:02 PM.

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