View Single Post
12/19/14, 12:57 AM   #1
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Libraries & Saved Variables

I have a couple of addons that work with tracking needed traits & recipes. I was "hoping" to find a way for them to share that information (and with other addons) so they don't all have to do the same work.
I thought about writing a library, which works, but I can not get saved variables to work with it. I figured libraries probably weren't really supposed to be saving things, but was hoping to find a way around it. I managed to get it to save the information, by doing:
Lua Code:
  1. local MAJOR, MINOR = "LibNeed4Research-1.0", 3
  2. local ln4r, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
  3. if not ln4r then return end
  4.  
  5. local function OnAddOnLoaded(_event, _sAddonName)
  6.     if _sAddonName == "ZO_Ingame" then
  7.         ln4r:Initialize()
  8.     end
  9.     ln4r.asv = ZO_SavedVars:NewAccountWide("LibNeed4ResearchVars", 1, nil, varDefaults)
  10.     ACV = ln4r.asv
  11.  
  12.     EVENT_MANAGER:UnregisterForEvent("LibNeed4Research", EVENT_ADD_ON_LOADED)
  13. end
  14. EVENT_MANAGER:RegisterForEvent("LibNeed4Research", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
It creates a saved variable file & writes to it, but it seems like it won't reload it. It seems like it is reinitializing the varDefaults variables every time. I'm guessing its just not possible?
I tried to look at the zo_savedvars.lua to figure out how it is loaded to see what is wrong, but I didn't quite understand it all.

So before I give up on it and scrap the whole thing I figured I'de give it a shot and ask.
Is this possible to do somehow without installing it as a stand alone addon? I just don't know if people would want to bother with installing some separate addon that does nothing but track data.
  Reply With Quote