Thread Tools Display Modes
04-10-13, 03:37 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
UnRegisterEvent

So i have some functions like thoose:

Code:
function PVPSound:RegisterAllEvent()
	PVPSoundFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
	PVPSoundFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
	PVPSoundFrame:RegisterEvent("PLAYER_DEAD")
	PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
	PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE")
	PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE")
	PVPSoundFrame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
	PVPSoundFrame:RegisterEvent("CHAT_MSG_RAID_BOSS_EMOTE")
	PVPSoundFrame:RegisterEvent("WORLD_MAP_UPDATE")
	PVPSoundFrameTwo:RegisterEvent("UPDATE_WORLD_STATES")
	PVPSoundFrameThree:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end

function PVPSound:UnregisterAllEvents()
	PVPSoundFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
	PVPSoundFrame:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
	PVPSoundFrame:UnregisterEvent("PLAYER_DEAD")
	PVPSoundFrame:UnregisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
	PVPSoundFrame:UnregisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE")
	PVPSoundFrame:UnregisterEvent("CHAT_MSG_BG_SYSTEM_HORDE")
	PVPSoundFrame:UnregisterEvent("CHAT_MSG_MONSTER_YELL")
	PVPSoundFrame:UnregisterEvent("CHAT_MSG_RAID_BOSS_EMOTE")
	PVPSoundFrame:UnregisterEvent("WORLD_MAP_UPDATE")
	PVPSoundFrameTwo:UnregisterEvent("UPDATE_WORLD_STATES")
	PVPSoundFrameThree:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
And a toggle button like that:

Code:
function PVPSound:OptionsEnableAddonButtonToggle(self)
	if self:GetChecked() then
		PS_EnableAddon = true
		PVPSound:RegisterAllEvent()
		PVPSoundKillSoundButton:Enable()
		PVPSoundKillSoundButtonText:SetTextColor(1, 1, 1)
		PVPSoundMultiKillSoundButton:Enable()
		PVPSoundMultiKillSoundButtonText:SetTextColor(1, 1, 1)
		UIDropDownMenu_EnableDropDown(PVPSoundSoundPackDropDown)
		UIDropDownMenu_EnableDropDown(PVPSoundSoundPackLanguageDropDown)
		UIDropDownMenu_EnableDropDown(PVPSoundSoundChannelDropDown)
	else
		PS_EnableAddon = false
		PVPSound:UnregisterAllEvents()
		PVPSoundKillSoundButton:Disable()
		PVPSoundKillSoundButtonText:SetTextColor(0.5, 0.5, 0.5)
		PVPSoundMultiKillSoundButton:Disable()
		PVPSoundMultiKillSoundButtonText:SetTextColor(0.5, 0.5, 0.5)
		UIDropDownMenu_DisableDropDown(PVPSoundSoundPackDropDown)
		UIDropDownMenu_DisableDropDown(PVPSoundSoundPackLanguageDropDown)
		UIDropDownMenu_DisableDropDown(PVPSoundSoundChannelDropDown)
	end
	--print(PS_EnableAddon)
end
All working fine, but every time i unregister "CHAT_MSG_BG_SYSTEM_ALLIANCE" or "CHAT_MSG_BG_SYSTEM_HORDE" then the eventhandler brokes, and doesnt register thoose events (Unless i "/reload" with checked enable button.):

Code:
local PVPSoundFrame = CreateFrame("Frame", "PVPSoundFrame")
PVPSoundFrame:RegisterEvent("ADDON_LOADED")

function PVPSound:OnLoad()
	if PS_EnableAddon == true then
		PVPSoundFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
		PVPSoundFrame:RegisterEvent("ZONE_CHANGED_NEW_AREA")
		PVPSoundFrame:RegisterEvent("PLAYER_DEAD")
		PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_NEUTRAL")
		PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_ALLIANCE")
		PVPSoundFrame:RegisterEvent("CHAT_MSG_BG_SYSTEM_HORDE")
		PVPSoundFrame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
		PVPSoundFrame:RegisterEvent("CHAT_MSG_RAID_BOSS_EMOTE")
		PVPSoundFrame:RegisterEvent("WORLD_MAP_UPDATE")
	end
end

local PVPSoundFrameTwo = CreateFrame("Frame", "PVPSoundFrameTwo")

function PVPSound:OnLoadTwo()
	if PS_EnableAddon == true then
		PVPSoundFrameTwo:RegisterEvent("UPDATE_WORLD_STATES")
	end
end

local PVPSoundFrameThree = CreateFrame("Frame", "PVPSoundFrameThree")

function PVPSound:OnLoadThree()
	if PS_EnableAddon == true then
		PVPSoundFrameThree:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
	end
end

function PVPSound:OnEvent(event, ...)
    if event == "CHAT_MSG_BG_SYSTEM_ALLIANCE" or event == "CHAT_MSG_BG_SYSTEM_HORDE" then
        -- DONT RUNS WHEN BUTTON TOGGLED
    end
end

PVPSoundFrame:SetScript("OnEvent", PVPSound.OnEvent)
Dont really get whats the problem.
  Reply With Quote
04-10-13, 07:21 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
RegisterAllEvents and UnregisterAllEvents are frame API.

Did you really intend to use those function names?
  Reply With Quote
04-10-13, 07:40 AM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Dridzt View Post
RegisterAllEvents and UnregisterAllEvents are frame API.

Did you really intend to use those function names?
They sohuld be local in my addon.
  Reply With Quote
04-10-13, 07:55 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Can't tell that from the first snippet.

What I'm saying is that if you intended to unregister a specific list of events but keep responding to a specific event, using the frame API variant kills all event handling.
  Reply With Quote
04-10-13, 09:34 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Dridzt View Post
Can't tell that from the first snippet.

What I'm saying is that if you intended to unregister a specific list of events but keep responding to a specific event, using the frame API variant kills all event handling.
Yeah, changed the function names, now its working, have no clue what was wrong with it tho.

I wanted to use my function because i didnt want to kill all events just some specific ones.
I want to keep the "ADDON_LOADED" event.

Last edited by Resike : 04-10-13 at 10:54 AM.
  Reply With Quote
04-10-13, 10:13 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Having a local reference to a global function that is changed from said global does not work. You can hook the global into a local function and change the way it responds, but you cannot directly change the global function or bypass it simply by creating a local variable with the same name.

That's like saying "my local apple is the same as the world's oranges, but the world's oranges are not my apple."
  Reply With Quote
04-10-13, 10:35 AM   #7
Sharparam
A Flamescale Wyrmkin
 
Sharparam's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 102
Not sure where you're getting "can't bypass" from, that is definitely possible:

Code:
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> function g() print "hello world" end
> local function g() print "override" end g()
override
I probably misinterpreted your message though :P
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UnRegisterEvent


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