Originally Posted by Garkin
SavedVariables are available when EVENT_ADD_ON_LOADED is triggered for your addon, not sooner. If you try to use saved variables when the ZO_Ingame is loaded, your variables are not ready yet and will be overwritten when initialized.
Loading order of addons is always:
1 - ZO_IngameLocalization
2 - ZO_Libraries
3 - ZO_Common
4 - ZO_Ingame
5 - from here starts your addons in (probably) random order
As votan said - if you want to have saved variables, you must specify global reference in addon manifest. If you have addon manifest, EVENT_ADD_ON_LOADED will be triggered for your library, so you can use it.
|
Awesome, thanks again for the help!
Well it could use a little more testing but so far it seems like I managed to get it to work using the library with two different addons.
I managed to get it to work by doing this specifying two SavedVariables & the path to the library in each addon.
Lua Code:
## Title: Click4Info
## APIVersion: 100010
## OptionalDependsOn: LibAddonMenu-2.0
## SavedVariables: Click4InfoSavedVars
## SavedVariables: Need4ResearchVars
## Version: 1.5
## Author: Circonian
## Description: Circonians Click4Info Version 1.5
libs\LibStub\LibStub.lua
libs\LibNeed4Research\LibNeed4Research.lua
and then having the library load when the addon that contains it is loaded
(I had to manually put the addons name in there though):
Lua Code:
-- This is code from the library file, not the addon
local function OnAddOnLoaded(_event, _sAddonName)
-- had to manually change this to the owning addon
if _sAddonName == Click4Info.name then
ln4r:Initialize()
end
end
function ln4r:Initialize()
ln4r.AccountSavedVariables = ZO_SavedVars:NewAccountWide("LibNeed4ResearchVars", 1, nil, varDefaults)
ASV = ln4r.AccountSavedVariables
UpdateTables()
EVENT_MANAGER:UnregisterForEvent("LibNeed4Research", EVENT_ADD_ON_LOADED)
end
It reads & writes the saved variables to each of the addons saved variable files and that will work just fine for me & my addons. But
I was wondering if there is any way to grab the addon name that is loading the library?
Some way to be able to set the addon name dynamically in the libraries OnAddOnLoaded :
Lua Code:
-- This is the one in my library file.
local function OnAddOnLoaded(_event, _sAddonName)
if _sAddonName == <to set this to the owning addons name> then
ln4r:Initialize()
end
end
So that addon developers don't have to modify the library file to put their addon name in there?