View Single Post
02-02-24, 01:03 PM   #1
Stormfather
A Defias Bandit
Join Date: Feb 2024
Posts: 2
Exclamation AceDB not persisting options between sessions

Hi all, I maintain a simple addon that gives you random hearthstone every time, I'm trying to make an options panel for you to select which HS you'd like to be in the random pool.
I've changed my code so the options are taken into account and that works, there's a page for the addon with checkboxes for all HS and if a HS is unchecked it never gets selected.
However once I close the game or reload these options vanish and I can't find any reference to them in Saved variables.

The bits I think are important:


Code:
local function InitializeDB()
	local defaults = {
		profile = {}
	}
	for key, _ in pairs(AllHearthToyIndex) do
		defaults.profile[key] = true
	end
	RandomHearthToySettings = LibStub("AceDB-3.0"):New("RandomHearthToyDB", defaults, true)
	DevTools_Dump({ RandomHearthToySettings });
end


-- Define your addon
local RandomHearthToy = AceAddon:NewAddon("RandomHearthToy", "AceConsole-3.0")

local function registerOptions()
	InitializeDB()
	-- Define your options table
	local options = {
		name = "RandomHearthToy Options",
		type = "group",
		args = {}
	}

	-- For each hearthstone, create an option
	for k, hearthstone in pairs(AllHearthToyIndex) do
		options.args["hearthstone" .. k] = {
				type = "toggle",
				name = tostring(hearthstone["name"]),
				desc = "Toggle " .. tostring(hearthstone["name"]),
				get = function() return RandomHearthToySettings.profile[k] end,
				set = function(_, value) RandomHearthToySettings.profile[k] = value end,
		}
	end

	-- Register your options table with AceConfig
	AceConfig:RegisterOptionsTable("RandomHearthToy", options)

	-- Add the options table to the Blizzard Interface Options
	AceConfigDialog:AddToBlizOptions("RandomHearthToy", "RandomHearthToy")

end


-- Setting up a frame to wait and see if the toybox is loaded before getting stones on login.
local timeOut = 10 --Delay for checking stones.
C_Timer.After(timeOut, function()
    local ticker
    ticker = C_Timer.NewTicker(1, function()
  		if C_ToyBox.GetNumToys() > 0 then
			registerOptions()
  			GetLearnedStones()
  			if RHTInitialized then
  				SetRandomHearthToy()
  				print "RHT initialized" -- uncomment for debugging future versions
  				ticker:Cancel()
  			end
  		end
    end)
end)

Full version if needed.

I was looking at examples of other addons and the ACE docs and seems to me this should just work and ran out of ideas of what to check, debug or try.

I'm sorry my LUA is horrible, this is my first addon and LUA project ever when I decided to update someone else's dead addon.

Thanks everyone for their time.
  Reply With Quote