Quantcast
HookScript mystery?? - WoWInterface
Thread Tools Display Modes
10-30-20, 11:04 PM   #1
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 256
HookScript mystery??

Can anybody explain the logic of this behaviour??

I am hooking OnTooltipSetItem and OnTooltipCleared of GameTooltip at two different times: when loading the addon and again with a 1 second delay:

Code:
GameTooltip:HookScript("OnTooltipSetItem", function() print("INIT >> SetItem") end)
GameTooltip:HookScript("OnTooltipCleared", function() print("INIT << Cleared") end)

C_Timer.After(1, function()
  GameTooltip:HookScript("OnTooltipSetItem", function() print("WAIT >> SetItem") end)
  GameTooltip:HookScript("OnTooltipCleared", function() print("WAIT << Cleared") end)
end)
Then, when the mouse cursor enters an item icon, I get the following:
Code:
INIT >> SetItem
INIT << Cleared
WAIT << Cleared
WAIT >> SetItem
INIT << Cleared
WAIT << Cleared
As the tooltip is permantenyl refreshed, this pattern of lines is actually repeated.
But what I don't understand is why the "INIT" prints get executed first for BOTH SetItem and Cleared, and only then the "WAIT" prints get executed but in the opposite order (first Cleared then SetItem)?

I would have expected that INIT and WAIT are always executed one after the other. So what does it matter if I set the hook when loading the addon or with a delay?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
10-31-20, 01:52 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 799
May be the first thing when Setitem fires is that it calls a clear for the tooltip?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-31-20, 04:35 AM   #3
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 256
OK, I think my working example was not the best way to demonstrate it.
Let me put it this way:

Code:
GameTooltip:HookScript("OnTooltipSetItem", function() print(GetTime(), "SetItem") end)
GameTooltip:HookScript("OnTooltipCleared", function() print(GetTime(), "Cleared") end)
leads to:

Code:
1225.517 SetItem
1225.517 Cleared
1225.689 Cleared
1225.689 SetItem
1225.689 Cleared
1225.89 Cleared
1225.89 SetItem
1225.89 Cleared
1226.093 Cleared
1226.093 SetItem
1226.093 Cleared
1226.297 Cleared
1226.297 SetItem
1226.297 Cleared
1226.502 Cleared
1226.502 SetItem
1226.502 Cleared
1226.705 Cleared
1226.705 SetItem
1226.705 Cleared
...

Whereas,

Code:
C_Timer.After(1, function()

  GameTooltip:HookScript("OnTooltipSetItem", function() print(GetTime(), "SetItem") end)
  GameTooltip:HookScript("OnTooltipCleared", function() print(GetTime(), "Cleared") end)

end)
leads to

Code:
1340.647 Cleared
1340.647 SetItem
1340.743 Cleared
1340.743 Cleared
1340.743 SetItem
1340.946 Cleared
1340.946 Cleared
1340.946 SetItem
1341.15 Cleared
1341.15 Cleared
1341.15 SetItem
1341.353 Cleared
1341.353 Cleared
1341.353 SetItem
1341.555 Cleared
1341.555 Cleared
1341.555 SetItem
...
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
10-31-20, 04:41 AM   #4
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 256
So, this is interesting:

I disabled all other addons, and now I get the same for both cases:

Code:
1551.817 SetItem
1551.85 Cleared
1551.85 SetItem
1552.051 Cleared
1552.051 SetItem
1552.252 Cleared
1552.252 SetItem
1552.453 Cleared
1552.453 SetItem
1552.654 Cleared
1552.654 SetItem
1552.855 Cleared
1552.855 SetItem
1553.057 Cleared
1553.057 SetItem
...
What does this mean?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
10-31-20, 04:48 AM   #5
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 256
Originally Posted by Rilgamon View Post
May be the first thing when Setitem fires is that it calls a clear for the tooltip?
OK, turns out you were right. I got another addon hooking OnTooltipSetItem executing ClearLines().
If that goes first, it's like:

Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
  self:ClearLines()
  self:AddLine("hi")
end)

GameTooltip:HookScript("OnTooltipSetItem", function() print(GetTime(), "SetItem") end)
GameTooltip:HookScript("OnTooltipCleared", function() print(GetTime(), "Cleared") end)
Leading to

Code:
3679.479 Cleared
3679.479 SetItem
3679.629 Cleared
3679.629 Cleared
3679.629 SetItem
3679.831 Cleared
3679.831 Cleared
3679.831 SetItem
3680.031 Cleared
3680.031 Cleared
3680.031 SetItem
...


If it comes second, it's like:

Code:
GameTooltip:HookScript("OnTooltipSetItem", function() print(GetTime(), "SetItem") end)
GameTooltip:HookScript("OnTooltipCleared", function() print(GetTime(), "Cleared") end)

GameTooltip:HookScript("OnTooltipSetItem", function(self)
  self:ClearLines()
  self:AddLine("hi")
end)
leading to


Code:
4264.37 SetItem
4264.37 Cleared
4264.553 Cleared
4264.553 SetItem
4264.553 Cleared
4264.754 Cleared
4264.754 SetItem
4264.754 Cleared
4264.956 Cleared
4264.956 SetItem
4264.956 Cleared
...
Thanks!

Last edited by LudiusMaximus : 10-31-20 at 05:24 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » HookScript mystery??

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