Thread Tools Display Modes
09-25-16, 01:47 PM   #1
b_coli
A Kobold Labourer
Join Date: Sep 2016
Posts: 1
Testing Events

I have an addon (very simple, just learning) that outputs "congrats" to the chat whenever the player levels up. It works, but obviously leveling up each time I want to check a change isn't ideal. Since the frame has registered the "PLAYER_LEVEL_UP" event, is there a way to fire off a fake "PLAYER_LEVEL_UP" event to trick my mod? Or do I just have to add a 'testing' input parameter and fire the script if the event happens OR if the flag is set? I'm including the code below even though it's pretty basic at this point.

Code:
    local Congrats_Frame = CreateFrame("Frame");
    Congrats_Frame:RegisterEvent("PLAYER_LEVEL_UP");
    Congrats_Frame:SetScript("OnEvent", function(self, event, ...)
        print('congrats'); 
    end)
    print('testing');
  Reply With Quote
09-25-16, 01:54 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Either just create a named function for the OnEvent handler, and then call that whenever you want:
Code:
local function onEvent(self, event, ...)
	print('congrats')
end

Congrats_Frame:SetScript("OnEvent", onEvent)

-- test
onEvent(Congrats_Frame, "PLAYER_LEVEL_UP")
..or get the applied function with GetScript and do the same:
Code:
Congrats_Frame:SetScript("OnEvent", function onEvent(self, event, ...)
	print('congrats')
end)

-- test
Congrats_Frame:GetScript("OnEvent")(Congrats_Frame, "PLAYER_LEVEL_UP")
You don't need to pass any arguments if you're not going to use them.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Testing Events

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