View Single Post
12/19/14, 05:10 PM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Garkin View Post
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:
  1. ## Title: Click4Info
  2. ## APIVersion: 100010
  3. ## OptionalDependsOn: LibAddonMenu-2.0
  4. ## SavedVariables: Click4InfoSavedVars
  5. ## SavedVariables: Need4ResearchVars
  6. ## Version: 1.5
  7. ## Author: Circonian
  8. ## Description: Circonians Click4Info Version 1.5
  9.  
  10. libs\LibStub\LibStub.lua
  11. 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:
  1. -- This is code from the library file, not the addon
  2. local function OnAddOnLoaded(_event, _sAddonName)
  3.         -- had to manually change this to the owning addon
  4.     if _sAddonName == Click4Info.name then
  5.         ln4r:Initialize()
  6.     end
  7. end
  8. function ln4r:Initialize()
  9.     ln4r.AccountSavedVariables = ZO_SavedVars:NewAccountWide("LibNeed4ResearchVars", 1, nil, varDefaults)
  10.     ASV = ln4r.AccountSavedVariables
  11.     UpdateTables()
  12.     EVENT_MANAGER:UnregisterForEvent("LibNeed4Research", EVENT_ADD_ON_LOADED)
  13. 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:
  1. -- This is the one in my library file.
  2. local function OnAddOnLoaded(_event, _sAddonName)
  3.     if _sAddonName == <to set this to the owning addons name> then
  4.         ln4r:Initialize()
  5.     end
  6. end
So that addon developers don't have to modify the library file to put their addon name in there?
  Reply With Quote