Thread Tools Display Modes
07-30-19, 01:02 PM   #1
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
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?
  Reply With Quote
07-30-19, 01:48 PM   #2
pas06
A Theradrim Guardian
Join Date: Apr 2009
Posts: 62
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

Last edited by pas06 : 07-30-19 at 02:01 PM.
  Reply With Quote
07-30-19, 11:23 PM   #3
Lybrial
A Flamescale Wyrmkin
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 120
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » HookScript after SetScript 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