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…
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)
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
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
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 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
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?
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!
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’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.