Thread Tools Display Modes
02-14-17, 04:22 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Any possible ways to fire fake event for testing?

Hi again all,

When we make an addon, would there be any possible ways to fire a fake event?

I'm asking this because some events like "PLAYER_LEVEL_UP" are honestly difficult to deal with as you really have to create a new character to test.

Any ideas please?

Thank you.
  Reply With Quote
02-14-17, 04:22 AM   #2
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
I've been researching this for half an hour and could've not found any related solutions D:
  Reply With Quote
02-14-17, 06:45 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Something like this will do the trick. Keep in mind, this will cause taint.

Lua Code:
  1. local function FireEvent(event,...)
  2.     event=event:upper();--  Events are always uppercase
  3.     local list={GetFramesRegisteredForEvent(event)};--  Get list of frames
  4.     for _,frame in ipairs(list) do
  5.         local func=frame:GetScript("OnEvent");--    Get OnEvent handler
  6.         if func then func(frame,event,...); end--   Run it if there is one
  7.     end
  8. end

Alternatively, you can grab the OnEvent handler from your frame using frame:GetScript("OnEvent") and manually pass the arguments it needs. If you have the handler stored in a variable, you can just call it directly with the same arguments.
__________________
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 : 02-14-17 at 06:51 AM.
  Reply With Quote
02-14-17, 03:10 PM   #4
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Thank you so much SDPhantom!

I'm currently out, but will definitely test this as soon as I get back home and let you know how I went

EDIT: It worked well!

Thanks a lot !!

Last edited by Layback_ : 02-15-17 at 04:14 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Any possible ways to fire fake event for testing?


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