[Era] Help with ADDON_LOADED event -- only firing once?

Hey, I’m trying to do some setup for saved variables. I’m googling around and it looks like ADDON_LOADED, when fired for your addon, is the appropriate place to do this. Supposedly this event should get fired for every addon, once it’s done loading.

For me though, it looks like the event is only firing once, for a single addon (usually some Blizzard one). Here’s some test code I have…

local testFrame = CreateFrame("Frame")
testFrame:RegisterEvent("ADDON_LOADED")
testFrame:SetScript(
	"OnEvent",
	function(self, event, ...)
		print("**** EVENT: " .. event)
		DevTools_Dump({...})
	end
)

It only sees a single occurrence and the output is this…

**** EVENT: ADDON_LOADED
[1]=“Blizzard_CombatText”,
[2]=false

Does anybody have any ideas about what I might be doing wrong here?

ADDON_LOADED fires first for your addon and then again for every addon that loads after it ie. There may be addons that load before yours and you won’t receive and event for them.

For SavedVariables, unless you have a specific reason otherwise then the PLAYER_LOGIN event is probably more useful as it only fires once and only after all initital addons (and their SavedVariables) have loaded and before the first PLAYER_ENTERING_WORLD event (any Load On Demand addons may load after entering the world)

testFrame:RegisterEvent("PLAYER_LOGIN")
testFrame:SetScript("OnEvent", function(self, event, ...)
	print("**** EVENT: ", event, ...)
	-- SavedVariables stuff...
end)

Does your .toc have any dependency addons listed, marked LOD/LoadWith?

Hey there, thanks for your reply :slight_smile:

Well, I never even receive an event for my own addon. It only ever fires once and the argument never contains my addon name.

I was following a guide here: https://wowwiki-archive.fandom.com/wiki/Saving_variables_between_game_sessions

I’ll give things a try with PLAYER_LOGIN though and see what happens.

No. I didn’t post the .toc for the test code I posted above, but it only contains the lua file with that code.

Try it using the code I posted (without using DevTools which I believe goes through the chat AddMessage).

local testFrame = CreateFrame("Frame")
testFrame:RegisterEvent("ADDON_LOADED")
testFrame:SetScript(
	"OnEvent",
	function(self, event, ...)
		print("**** EVENT: " .. event)
		local args={...}
		print(args[1])
	end
)

I removed the DevTools_Dump and replaced it with a print and nope, still only a single occurrence of the ADDON_LOADED event, not for my addon.

**** EVENT: ADDON_LOADED
Blizzard_CombatText

Even if I don’t print the args I just get the one event. If you run that same code, does it fire multiple times for you? If it does, are you in the Era client?

I haven’t yet tried saved variable loading in PLAYER_LOGIN, I was working on something else. I’m going to give it a go now :smiley:


UPDATE:

I just gave this a test. I’m definitely getting more predictable behaviour now but I have other problems… they’re just my own fault :wink:

Still, I’m curious about the behaviour of ADDON_LOADED. All the documentation seems to suggest it should fire for each and every addon, but for me it’s only firing for a built-in Blizzard one. It’s usually the combat text I quoted above but sometimes its a different Blizzard one.

The full contents of the .toc and .lua file(s) might help.

That code is the full contents of the .lua file. The .toc file is as minimal as you need…

So assuming you put the lua code in TubblyTest.lua, then your .toc file would be…

TubblyTest.lua

The Blizzard Combat Text and Blizzard Time Manager addons are marked Load On Demand (I think based on a CVar) and in the natural order of the will load after the initial addons (including 3rd party)

That you’re not seeing anything else might mean you’re getting an error somewhere in your code. If you install:
https://www.curseforge.com/wow/addons/bug-grabber
AND
https://www.curseforge.com/wow/addons/bugsack

it might show these up.

There is no other code… it’s just what I posted above. I can certainly try those tools but I think we might be barking up the wrong tree as its an extremely simplified example.

Have you tried the code I posted and see a different result than I’m experiencing?

My .lua with just

local testFrame = CreateFrame("Frame")
testFrame:RegisterEvent("ADDON_LOADED")
testFrame:SetScript("OnEvent",	function(self, event, ...)
	print("**** EVENT:", event, ...)
end)

prints:

  • TubblyTest
  • Blizzard_TimeManager
  • Blizzard_CombatText

TubblyTest is the only 3rd party addon in the folder.

Maybe copy/paste my code in case of non-printing character.

BTW, if you .toc only contains

TubblyTest.lua

Then SavedVariables arent going to work. You will at least have to add something like

## SavedVariables: TubblyTest_DATA

meaning your global SavedVariable name to use will be TubblyTest_DATA

Maybe also add

## Interface: 11505
## Title: Tubbly Test
## Version: 1.0.0
## Author: Tubbly

As these help with what shows in the addons list.

Yep, I used your code exactly and I only get:

**** EVENT: ADDON_LOADED Blizzard_CombatText false

I even restarted my client to ensure that nothing was hanging around somehow. I used exactly your code.

I think the only question left is… are you running this in the Classic Era client or a different one? If you’re also using Era then I’m kind of at a loss, but if you’re using a different client I can install that one and see what happens. I’ll have to do it later as I only have Era installed and the download will take some time.

That .toc was just for example test purposes. I’ve got everything working (including my saved variable) in my actual addon code now that I’m using the PLAYER_LOGIN event, so thank you for that tip! :heart:

At this point I think I’m trying to determine of the ADDON_LOADED event is bugged or not. If it is, I can log a post in another forum.

I ran in Classic Era. That said, there’s a lot in sync. between Era and Retail.

Yea, that’s the same as I’m running in. I’m completely at a loss as to why we would get different outputs here :frowning:

Thank you for trying, and for your help!

If your SVs were working (saving) then the .lua file was not the only thing in the .toc.

I’m sorry, I think there’s a misunderstanding here. The SavedVariables are unrelated to the conversation about ADDON_LOADED. That was just the event I was using to try to get SavedVariables working. In my main project, when I switched over to PLAYER_LOGIN, everything worked great.

In the separate conversation about ADDON_LOADED, I posted a simplified, sample .lua and .toc file for test purposes. There, the .lua file was the only thing in the .toc file.

Don’t worry about the SavedVariables part, that’s a different thing. I have it working thanks to your excellent suggestion.

Sometimes you need the whole picture when trying to debug something.

Have fun!

1 Like