Thread Tools Display Modes
07-07-15, 01:26 PM   #1
Jesus72
A Defias Bandit
Join Date: Jul 2015
Posts: 3
Simulating events

Hi,

I'm wondering if it's possible to send events that will be picked up by whatever is subscribed to that event?

I'm trying to debug something but it's quite difficult without actually doing the event.
I know I can send a false event to a specific OnEvent function but can't seem to recreate the issue that way.

The alternative question is, any reason why a prehook would fail to run when in LFG dungeon but work perfectly in a LFR raid?
Thanks

Last edited by Jesus72 : 07-07-15 at 01:47 PM.
  Reply With Quote
07-07-15, 02:18 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You can use GetFramesRegisteredForEvent() to get a list of frames that has the event registered. After that, you can try to grab each one's OnEvent handler and run it. Don't forget to include a reference to the frame itself and the event firing among the list of arguments when calling a frame's handler.
Lua Code:
  1. function FireEvent(event,...)
  2.     local framelist={GetFramesRegisteredForEvent(event)};
  3.     for i,j in ipairs(framelist) do
  4.         local func=j:GetScript("OnEvent");
  5.         if func then func(j,event,...); end
  6.     end
  7. end

In essence, LFD and LFR have two different sets of frames even though Blizzard has been trying to integrate them into the LFG template. It's one mess I really don't want to dive into.
__________________
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
07-07-15, 02:38 PM   #3
Jesus72
A Defias Bandit
Join Date: Jul 2015
Posts: 3
Ah that's great, thanks.

This seems to recreate the issue I'm facing.

Seems that if I call the frame's OnEvent directly as BlizzardFrame_OnEvent(BlizzardFrame, EVENT, ...) my prehook kicks in and works.

If I try and call it as you did using GetScript("OnEvent") my prehook gets ignored.
  Reply With Quote
07-07-15, 03:27 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
What happens a lot is Blizzard defines the function in Lua, then links it in XML. This means the Lua function isn't really called anymore from the global namespace where your hook resides. You need to hook the frame's handler directly.

To understand this better, when you hook a function, you're essentially creating a new function that calls the old one. Right now, you're just sticking it in the global namespace where the old one was. However, when the function was registered as a frame's handler, it stored the pointer to the old function and continues calling it directly. A cheap way to have your hook apply to the frame's handler is to re-register it.

Code:
BlizzardFrame:SetScript("OnEvent",BlizzardFrame_OnEvent);
__________________
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)

Last edited by SDPhantom : 07-07-15 at 03:47 PM.
  Reply With Quote
07-07-15, 03:51 PM   #5
Jesus72
A Defias Bandit
Join Date: Jul 2015
Posts: 3
Originally Posted by SDPhantom View Post
What happens a lot is Blizzard defines the function in Lua, then links it in XML. This means the Lua function isn't really called anymore from the global namespace where your hook resides. You need to hook the frame's handler directly.

To understand this better, when you hook a function, you're essentially creating a new function that calls the old one. Right now, you're just sticking it in the global namespace where the old one was. However, when the function was registered as a frame's handler, it stored the pointer to the old function and continues calling it directly. A cheap way to have your hook apply to the frame's handler is to re-register it.

Code:
BlizzardFrame:SetScript("OnEvent",BlizzardFrame_OnEvent);
Thanks, that helps a lot.

Managed to get it working like this
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Simulating events


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