Thread Tools Display Modes
08-22-22, 07:48 AM   #1
nyxxir
A Defias Bandit
Join Date: Aug 2022
Posts: 2
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)...
  Reply With Quote
08-22-22, 02:25 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
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)
  Reply With Quote
08-23-22, 07:20 AM   #3
nyxxir
A Defias Bandit
Join Date: Aug 2022
Posts: 2
Originally Posted by Kanegasi View Post
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.
  Reply With Quote
08-23-22, 07:43 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
BugGrabber and BugSack work together for debugging addons.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
08-23-22, 02:59 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Why OnTooltipSetUnit callback is not working?

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