WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   HookScript mystery?? (https://www.wowinterface.com/forums/showthread.php?t=58357)

LudiusMaximus 10-30-20 11:04 PM

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?

Rilgamon 10-31-20 01:52 AM

May be the first thing when Setitem fires is that it calls a clear for the tooltip?

LudiusMaximus 10-31-20 04:35 AM

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
...


LudiusMaximus 10-31-20 04:41 AM

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?

LudiusMaximus 10-31-20 04:48 AM

Quote:

Originally Posted by Rilgamon (Post 337472)
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!


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

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