WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   ADDON_LOADED does not work (https://www.wowinterface.com/forums/showthread.php?t=52607)

evilbib 08-12-15 02:44 PM

ADDON_LOADED does not work
 
So this code below does nothing. No errors.
If I remove the "if addon" line it works, but then it will be executed multiple times. This did work before 6.2.

Somebody can help me?

Lua Code:
  1. local function ApplySkin(self, event, addon)
  2.     if addon == "Skada" then
  3.         local SkadaDisplayBar = Skada.displays["bar"]
  4.         hooksecurefunc(SkadaDisplayBar, "AddDisplayOptions", function(self, win, options)
  5.             options.titleoptions = nil
  6.             options.windowoptions = nil
  7.         end)
  8.         hooksecurefunc(SkadaDisplayBar, "Create", function(self, win)
  9.             local skada = win.bargroup         
  10.             local skadaBorder = CreateFrame("Frame", nil, skada, skada)
  11.             skadaBorder:SetAllPoints()
  12.             skadaBorder:CreateBeautyBorder(12)
  13.             skadaBorder:SetBeautyBorderPadding(3)
  14.         end)
  15.         hooksecurefunc(SkadaDisplayBar, "ApplySettings", function(self, win)
  16.             local skada = win.bargroup
  17.             skada:SetBackdrop({
  18.                 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  19.                 edgeFile = nil, tile = false, tileSize = 0, edgeSize = 32,
  20.                 insets = { left = 0, right = 0, top = 0, bottom = 0 }
  21.             })
  22.             skada:SetBackdropColor(0, 0, 0, 0.8)
  23.         end)
  24.     end
  25. end
  26.  
  27. local f = CreateFrame("Frame")
  28. f:RegisterEvent("ADDON_LOADED")
  29. f:SetScript("OnEvent", ApplySkin)

Tim 08-12-15 02:50 PM

Do keep in mind that that your addon can load before or after Skada. If your addon loads before Skada then there's nothing to apply the skin to. However, if it loads afterwards then you would be good to go.

Try adding Skada to your dependencies (optional or required, whichever) and go from there. Also remember to report lua errors.

evilbib 08-12-15 03:08 PM

Quote:

Originally Posted by Tim (Post 310300)
Do keep in mind that that your addon can load before or after Skada. If your addon loads before Skada then there's nothing to apply the skin to. However, if it loads afterwards then you would be good to go.

Try adding Skada to your dependencies (optional or required, whichever) and go from there. Also remember to report lua errors.

Skada is in my dependencies. Also I gave my addon an letter that comes after s but nothing helps and like I said there are no LUA errors.

Banknorris 08-12-15 03:20 PM

You can also check for the existence of SkadaDisplayBar

Code:

if SkadaDisplayBar then
    --call a function that hooks SkadaDisplayBar
else
    f:RegisterEvent("ADDON_LOADED")
end


elcius 08-12-15 04:05 PM

most likely skada is not ready, check when it actually builds the displays, because i doubt it does it on load.
the most resilient solution would be to just wait until it's ready:
Code:

C_Timer.NewTicker(0.1, function(self)
        local SkadaDisplayBar = Skada.displays["bar"];
        if not SkadaDisplayBar then -- you may need to check other stuff also
                return
        end
        hooksecurefunc(SkadaDisplayBar, "AddDisplayOptions", function(self, win, options)
                options.titleoptions = nil
                options.windowoptions = nil
        end)
        hooksecurefunc(SkadaDisplayBar, "Create", function(self, win)
                local skada = win.bargroup         
                local skadaBorder = CreateFrame("Frame", nil, skada, skada)
                skadaBorder:SetAllPoints()
                skadaBorder:CreateBeautyBorder(12)
                skadaBorder:SetBeautyBorderPadding(3)
        end)
        hooksecurefunc(SkadaDisplayBar, "ApplySettings", function(self, win)
                local skada = win.bargroup
                skada:SetBackdrop({
                        bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
                        edgeFile = nil, tile = false, tileSize = 0, edgeSize = 32,
                        insets = { left = 0, right = 0, top = 0, bottom = 0 }
                })
                skada:SetBackdropColor(0, 0, 0, 0.8)
        end)
        self:Cancel();
end, 1e4);


Seerah 08-12-15 07:05 PM

If Skada is in your dependencies, then it will be loaded before your addon. This means that Skada's ADDON_LOADED event will fire before your code is run. Which means that it's loaded already, and you don't need to wait for it.

evilbib 08-12-15 07:16 PM

Lua Code:
  1. if event == "PLAYER_ENTERING_WORLD" then
  2.         C_Timer.NewTicker(0.1, function(self)
  3.             local SkadaDisplayBar = Skada.displays["bar"]
  4.             if not SkadaBarWindowDamage then
  5.                 return
  6.             end
  7.             SkadaBarWindowDamage:CreateBeautyBorder(12)
  8.             hooksecurefunc(SkadaDisplayBar, "AddDisplayOptions", function(self, win, options)
  9.                 options.titleoptions = nil
  10.                 options.windowoptions = nil
  11.             end)
  12.             hooksecurefunc(SkadaDisplayBar, "ApplySettings", function(self, win)
  13.                 local skada = win.bargroup
  14.                 skada:SetBackdrop({
  15.                     bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  16.                     edgeFile = nil, tile = false, tileSize = 0, edgeSize = 32,
  17.                     insets = { left = 0, right = 0, top = 0, bottom = 0 }
  18.                 })
  19.                 skada:SetBackdropColor(0, 0, 0, 0.8)
  20.             end)
  21.             self:Cancel()
  22.         end, 1e4)
  23.     end

This is what I have now and it works.

But still I wonder why it stopped working all of a sudden, I also tried older Skada versions.

meribold 08-13-15 09:21 AM

Quote:

Originally Posted by Seerah (Post 310306)
If Skada is in your dependencies, then it will be loaded before your addon. This means that Skada's ADDON_LOADED event will fire before your code is run. Which means that it's loaded already, and you don't need to wait for it.

This. Think about it, when the client gets to loading your event handler, ADDON_LOADED has already been posted for Skada, while your AddOn had no chance to react to it yet.

The question is why this even used to work.

Edit: I would suggest just checking for your own AddOn's name instead of "Skada".

evilbib 08-13-15 11:27 AM

Quote:

Originally Posted by meribold (Post 310311)
This. Think about it, when the client gets to loading your event handler, ADDON_LOADED has already been posted for Skada, while your AddOn had no chance to react to it yet.

The question is why this even used to work.

Edit: I would suggest just checking for your own AddOn's name instead of "Skada".

I added Skada to my dependencies after the first answer.

Lombra 08-13-15 02:44 PM

Make a simpler program to troubleshoot it from the top. Maybe disable some other addons if you're getting spammed by this.

Code:

if IsAddOnLoaded("Skada") then
        print("Skada is already loaded")
else
        local f = CreateFrame("Frame")
        f:RegisterEvent("ADDON_LOADED")
        f:SetScript("OnEvent", print)
end


evilbib 08-14-15 01:14 PM

Sorry guys I am retarded, I updated the addon nCore which has skada as OptionalDeps. I tried reloading with only skada and my addon but since nCore was already loaded I didn't notice. Now I removed skada from nCore and my initial code works again.


All times are GMT -6. The time now is 02:22 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI