Without seeing all your code it's hard to pinpoint your problem, but I've never had a problem with ADDON_LOADED firing before the saved vars are loaded.
In fact, here is some sample code that I just tested and it worked every time for 20 logout/login cycles. The times loaded incremented as expected every time without fail.
TestSV.toc
Code:
## Interface: 20400
## Title: TestSV
## SavedVariables: TestSV
TestSV.lua
TestSV.lua
Code:
local function OnEvent(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "TestSV" then
self:UnregisterEvent("ADDON_LOADED") -- Don't need to know about others
if not TestSV then TestSV = {} end
TestSV.timesLoaded = (TestSV.timesLoaded or 0) + 1
ChatFrame1:AddMessage("TestSV Times Loaded: " .. TestSV.timesLoaded)
end
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", OnEvent)