View Single Post
02-28-13, 03:27 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem is that in this code:
Code:
if not IsAddOnLoaded("Chatter") then
    self:RegisterEvent("ADDON_LOADED")
    self:Hide()
else
    self:ConditionalShow()
end

-- define a function so we dont have to paste the same code in the onevent box.
function self:ConditionalShow()
    if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
        self:Show()
    else
        kgPanels:FetchFrame("chatB"):Show()
        Bazooka.db:SetProfile("MayronUI2")
        self:Hide()
    end
    -- Chatter is loaded here so we dont have to listen to ADDON_LOADED anymore, clean up this frame
    self:UnregisterEvent("ADDON_LOADED")
    self:SetScript("OnEvent", nil)
    self.ConditionalShow = nil
end
The "ConditionalShow" method is not yet defined when you try to call it in the first block. You need to define the method first, and then check for Chatter and call it. Just swap the order of the blocks:
Code:
-- define a function so we dont have to paste the same code in the onevent box.
function self:ConditionalShow()
    if LibStub("AceAddon-3.0"):GetAddon("Chatter").db:GetCurrentProfile() == "MayronUI" then
        self:Show()
    else
        kgPanels:FetchFrame("chatB"):Show()
        Bazooka.db:SetProfile("MayronUI2")
        self:Hide()
    end
    -- Chatter is loaded here so we dont have to listen to ADDON_LOADED anymore, clean up this frame
    self:UnregisterEvent("ADDON_LOADED")
    self:SetScript("OnEvent", nil)
    self.ConditionalShow = nil
end

if not IsAddOnLoaded("Chatter") then
    self:RegisterEvent("ADDON_LOADED")
    self:Hide()
else
    self:ConditionalShow()
end
Also, (mainly directed at ravagernl) don't mix single- and double-quotes for defining strings. Pick one style and stick with it. I'd suggest double-quotes, since you'll want apostrophes in your strings more often than you'll want quotation marks, but either one is fine. Just don't use one on one line, and the other on the next line. It's like mixing tabs and spaces for indentation in the same file.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote