Thread Tools Display Modes
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
02-02-24, 01:19 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
Your .toc file requires a ## SavedVariables: entry that matches the name of your LibStub("AceDB-3.0"):New(...) setting

eg:
Code:
## SavedVariables: RandomHearthToyDB
This tells the game to write the variable(s) to disk when the player logs off/reloads.

There is also ## SavedVariablesPerCharacter: to save the information seperately for each character.

Many addons will create a single "global" variable set (## SavedVariables) and manage individual character information within that using profiles (sets of information that can be assigned to one or more characters)

More information Here
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-02-24 at 01:39 PM.
  Reply With Quote
02-02-24, 02:45 PM   #3
Stormfather
A Defias Bandit
Join Date: Feb 2024
Posts: 2
I'm an idiot, that was what I was missing!
Thank you
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » AceDB not persisting options between sessions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off