WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   HookScript after SetScript not working? (https://www.wowinterface.com/forums/showthread.php?t=57324)

Lybrial 07-30-19 01:02 PM

HookScript after SetScript not working?
 
Hi,

I thought Ace HookScript function would hook on any script and first process the handler
and after that the original function.

How ever when I do the following:

Lua Code:
  1. self.frame:SetScript("OnEvent", function()
  2.     print("original function");
  3. end);
  4.  
  5. self:HookScript(self.frame, "OnEvent", function()
  6.     print("hooked function");
  7. end);

"original function" will be printed but "hooked function" wont ever be printed.
So whats the thing about that?

pas06 07-30-19 01:48 PM

i feel like this should definitely work.

Code:


self.frame:SetScript("OnEvent", function()
    print("original function");
end);
 
self:HookScript(self.frame, "OnEvent", function()
    print("hooked function");
end);





in this code you are hooking different objects tho self and self.frame
it should work like that:
Code:


self.frame:SetScript("OnEvent", function()
    print("original function");
end);
 
self.frame:HookScript("OnEvent", function()
    print("hooked function");
end);

if you want to do it the way you did in your HookScript() you need to do the following (repalce colon with a simple dot)

Code:

self.frame.HookScript(self.frame, "OnEvent", function()
    print("hooked function");
end);

^ is equivalent to replacing the dot before HookScript() with a colon and removing the first argument

Lybrial 07-30-19 11:23 PM

I should have mentioned that im using Ace3 Hook mixin. So

Lua Code:
  1. self:HookScript(self.frame, ...

is fine. Btw If I do not have a `SetScript` for `OnEvent` and only perform the hook:

Lua Code:
  1. self:HookScript(self.frame, "OnEvent", function()
  2.     print("hooked function");
  3. end);

"hooked function" is getting printed. So it really only does not work when I did a `SetScript`
for `OnEvent` before hooking it.


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

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