Quantcast
ADDON_LOADED does not work - WoWInterface
Thread Tools Display Modes
08-12-15, 02:44 PM   #1
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
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)
  Reply With Quote
08-12-15, 02:50 PM   #2
Tim
A Frostmaul Preserver
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 285
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.
__________________
AddOns: Tim @ WoWInterface
Characters: Hunter, Mage, Priest, Monk, DH,
Battle Tag: Tim#11172
Current PC Setup: PCPartPicker List
  Reply With Quote
08-12-15, 03:08 PM   #3
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
Originally Posted by Tim View Post
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.
  Reply With Quote
08-12-15, 03:20 PM   #4
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
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
__________________
"In this world nothing can be said to be certain, except that fractional reserve banking is a Ponzi scheme and that you won't believe it." - Mandrill
  Reply With Quote
08-12-15, 04:05 PM   #5
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 71
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);

Last edited by elcius : 08-12-15 at 04:08 PM.
  Reply With Quote
08-12-15, 07:05 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,759
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-12-15, 07:16 PM   #7
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
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.

Last edited by evilbib : 08-12-15 at 07:20 PM.
  Reply With Quote
08-13-15, 09:21 AM   #8
meribold
A Murloc Raider
 
meribold's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2013
Posts: 5
Originally Posted by Seerah View Post
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".

Last edited by meribold : 08-13-15 at 09:25 AM.
  Reply With Quote
08-13-15, 11:27 AM   #9
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
Originally Posted by meribold View Post
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.
  Reply With Quote
08-13-15, 02:44 PM   #10
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
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
__________________
Grab your sword and fight the Horde!
  Reply With Quote
08-14-15, 01:14 PM   #11
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » ADDON_LOADED does not work

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