View Single Post
02-14-18, 11:10 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Layback_ View Post
So, AceDB object doesn't necessarily be initialized via AceAddon's OnInitialize method?
Nope!

Here's how you would adapt the example from the AceDB-3.0 documentation page to use it without AceAddon-3.0. Yellow parts are copied from the documentation:

Code:
-- declare defaults to be used in the DB
local defaults = {
  profile = {
    setting = true,
  }
}

-- Here we set up event handling, which as a happy coincidence,
-- replicates 99% of what anyone uses AceEvent for in just 3 lines of code:
local MyAddon = CreateFrame("Frame", ADDON_NAME)
MyAddon:SetScript("OnEvent", function(self, event, ...)
  return self[event](self, ...)
end)

-- Now we replicate the functionality of the OnInitialize method from
-- AceAddon-3.0 by registering for an event and declaring a function to handle it:
MyAddon:RegisterEvent("PLAYER_LOGIN")
function MyAddon:PLAYER_LOGIN()
  -- Assuming the .toc says ## SavedVariables: MyAddonDB
  self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true)
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 02-14-18 at 11:15 PM.
  Reply With Quote