WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   AceDB not persisting options between sessions (https://www.wowinterface.com/forums/showthread.php?t=59781)

Stormfather 02-02-24 01:03 PM

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.

Fizzlemizz 02-02-24 01:19 PM

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

Stormfather 02-02-24 02:45 PM

I'm an idiot, that was what I was missing!
Thank you


All times are GMT -6. The time now is 06:23 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI