Some things that should be mentioned:
- You've got a global function with the extremely generic name disableOrEnableQueueButton. That's asking for a naming conflict.
There's really no reason for that to be global, so I'd advise making it a local instead. - You're creating a new anonymous function to replace HonorFrameSoloQueueButton.Enable every time your events fire.
- In your "reenable" logic, you're setting HonorFrameSoloQueueButton.Enable = Enable. "Enable" is not assigned anywhere in your code, so unless you're lucky and another addon is setting that global (which is A Bad Thing™ on its own), you're just setting it to nil (which should, really, be throwing an error on the line after that - are you sure you have Lua errors enabled?)
- Your frames have generic names. While you only use the reference returned from CreateFrame anyway, so there's no conflicts in your code, it's still cluttering the global namespace (and might lead to conflicts for other addons that do use the global reference). As those frames aren't actually displayed anywhere, there's no real reason for them to have a name, either (frame names are, arguably, only useful for two things - to be displayed in /fstack, and to work with some (*shudder*) UI XML SecureTemplates that still use $parent in their name="" attribute).
- You have two separate frames for your two events. While it doesn't make much of a difference in this case, it's still bad practice. The second argument passed to your event handler is the event name of the event that triggered - use it.
- There's no reason to keep switching the enable function back and forth the way you do. What you (probably) want in your case is complete control over the HonorFrameSoloQueueButton's enabled state - so just take it.
Here's a cleaned-up version:
Code:
local empty = function() end
local loaded, enable, disable
local function disableOrEnableQueueButton()
if IsInGroup(LE_PARTY_CATEGORY_HOME) then
disable(HonorFrameSoloQueueButton)
else
enable(HonorFrameSoloQueueButton)
end
end
local function onEvent(self, event, name)
if event == "ADDON_LOADED" then
if name == "Blizzard_PVPUI" then
loaded, enable, disable = true, HonorFrameSoloQueueButton.Enable, HonorFrameSoloQueueButton.Disable
HonorFrameSoloQueueButton.Enable, HonorFrameSoloQueueButton.Disable = empty, empty
self:UnregisterEvent("ADDON_LOADED") -- it'll only fire once, so no reason to keep it registered and taking up resources
disableOrEnableQueueButton()
end
else
if loaded then
disableOrEnableQueueButton()
end
end
end
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", onEvent)
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("ADDON_LOADED")
Hope that helps. If you have any questions, feel free to ask.