Thread Tools Display Modes
01-26-18, 06:33 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
AceConfigRegistry's NotifyChange()

So, I'm more or less trying to confirm the purpose of this function. My assumption is that I call it to request an update to AceConfig's options? Their site doesn't provide much material on the function.

My code
Lua Code:
  1. local ACFG = LibStub("AceConfigRegistry-3.0")
  2. ACFG:RegisterOptionsTable("CustomAudio Spell Sounds", GetSpellOptions)
  3.  
  4. local ACD = LibStub("AceConfigDialog-3.0")
  5. ACD:AddToBlizOptions("CustomAudio Spell Sounds", "Spell Sounds", "CustomAudio")
  6.  
  7. -- I run this code when the player changes the active profile
  8. LibStub("AceConfigRegistry-3.0"):NotifyChange("CustomAudio Spell Sounds")

From what I've found, the code seems to be correct, but it doesn't actually update any of my config's values. Currently, when I try to update the active profile, I have to ReloadUI() to have the proper values appear.

Is there perhaps a different function/method I should be using to update my config's values?

Last edited by Sweetsour : 01-26-18 at 09:35 PM.
  Reply With Quote
01-26-18, 09:53 PM   #2
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,364
Correct me if I'm wrong, but, doesn't your "config" values go to your "SavedVariables"? Those don't get written until you either log off your character, reload the UI, or exit the game (or the game does a cinematic, I think). If that's the case, you wouldn't see them if you check for them and didn't do any of those.
__________________
Ahhhh, the vagueries of the aging mind. Wait.... What was I saying?


Carbonite <----- GitHub main module (Maps ONLY) download link. The other modules are also available on GitHub.
Carbonite-CLASSIC<----- GitHub link to Carbonite Classic. Thanks to ircdirk for this!
  Reply With Quote
01-27-18, 01:05 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Yea, I tried for hours, but I just ended up going with reloading the UI, lol.
  Reply With Quote
01-27-18, 01:38 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
What's your actual code?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-27-18, 01:58 PM   #5
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Lua Code:
  1. local function RefreshConfig()
  2.     foreach(LibStub("AceConfigRegistry-3.0").tables,function(k,v)
  3.         ACFG:NotifyChange(k)
  4.     end)
  5. end
  6.  
  7. function Ace3:OnProfileUpdate(event,db,profileKey)
  8.     if (db) then
  9.         ReloadUI()
  10.     end
  11.  
  12.     --What I've tried, but is currently commented
  13.     SCA.profile = self.db.profile
  14.     RefreshConfig()
  15. end
  16.  
  17. -- Event: ADDON_LOADED
  18. function Ace3:OnInitialize()
  19.     local about_panel = LibStub:GetLibrary("LibAboutPanel", true)
  20.  
  21.     if about_panel then
  22.         self.optionsFrame = about_panel.new(nil, "CustomAudio")
  23.     end
  24.  
  25.     self.db = LibStub("AceDB-3.0"):New("SCA_db", SCA.defaults)
  26.     SCA.profile = self.db.profile
  27.  
  28.     self.db.RegisterCallback(self, "OnNewProfile", "OnProfileUpdate")
  29.     self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileUpdate")
  30.     self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileUpdate")
  31.     self.db.RegisterCallback(self, "OnProfileReset", "OnProfileUpdate")
  32.  
  33.     self:SetupOptions()
  34. end
  35.  
  36. function Ace3:SetupOptions()
  37.     local ACFG = LibStub("AceConfigRegistry-3.0")
  38.     ACFG:RegisterOptionsTable("CustomAudio Quick Toggle", GetToggleOptions)
  39.     ACFG:RegisterOptionsTable("CustomAudio Spell Sounds", GetSpellOptions)
  40.     ACFG:RegisterOptionsTable("CustomAudio Defense Sounds", GetDefenseOptions)
  41.     ACFG:RegisterOptionsTable("CustomAudio Combat Sounds", GetCombatOptions)
  42.     ACFG:RegisterOptionsTable("CustomAudio Loot Sounds", GetLootOptions)
  43.     ACFG:RegisterOptionsTable("CustomAudio Chat Sounds", GetChatOptions)
  44.     ACFG:RegisterOptionsTable("CustomAudio Movement Sounds", GetMoveOptions)
  45.     ACFG:RegisterOptionsTable("CustomAudio Backup Sounds", GetBackupOptions)
  46.     ACFG:RegisterOptionsTable("CustomAudio Restore Sounds", GetRestoreOptions)
  47.     ACFG:RegisterOptionsTable("CustomAudio Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db,true))
  48.  
  49.     local ACD = LibStub("AceConfigDialog-3.0")
  50.     ACD:AddToBlizOptions("CustomAudio Quick Toggle", "Quick Toggle", "CustomAudio")
  51.     ACD:AddToBlizOptions("CustomAudio Spell Sounds", "Spell Sounds", "CustomAudio")
  52.     ACD:AddToBlizOptions("CustomAudio Defense Sounds", "Defense Sounds", "CustomAudio")
  53.     ACD:AddToBlizOptions("CustomAudio Combat Sounds", "Combat Sounds", "CustomAudio")
  54.     ACD:AddToBlizOptions("CustomAudio Loot Sounds", "Loot Sounds", "CustomAudio")
  55.     ACD:AddToBlizOptions("CustomAudio Chat Sounds", "Chat Sounds", "CustomAudio")
  56.     ACD:AddToBlizOptions("CustomAudio Movement Sounds", "Movement Sounds", "CustomAudio")
  57.     ACD:AddToBlizOptions("CustomAudio Backup Sounds", "Backup Sounds", "CustomAudio")
  58.     ACD:AddToBlizOptions("CustomAudio Restore Sounds", "Restore Sounds", "CustomAudio")
  59.     ACD:AddToBlizOptions("CustomAudio Profiles", "Profiles", "CustomAudio")
  60. end

The issue I'm having is when I make any profile changes, then try to access any part of my addon's config, I get Lua errors because values can't be found.

Last edited by Sweetsour : 01-27-18 at 02:59 PM.
  Reply With Quote
01-27-18, 03:48 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
This isn't your whole code, but I'll take a guess...

I have no idea what you're doing here:
Lua Code:
  1. foreach(LibStub("AceConfigRegistry-3.0").tables,function(k,v)
  2.         ACFG:NotifyChange(k)
  3.     end)

Every usage I've seen of this method is to call :NotifyConfig(ADDON_NAME_HERE)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-27-18, 03:57 PM   #7
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
In AceConfigRegistry-3.0.lua
Lua Code:
  1. function AceConfigRegistry:NotifyChange(appName)
  2.     if not AceConfigRegistry.tables[appName] then return end
  3.     AceConfigRegistry.callbacks:Fire("ConfigTableChange", appName)
  4. end

In my AceConfigRegistry.tables:


NotifyChange("CustomAudio") doesn't work

Last edited by Sweetsour : 01-27-18 at 08:42 PM.
  Reply With Quote
01-30-18, 07:52 AM   #8
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
NotifyChange is primarily used to update the SV table previously registered with AceDB whenever an external method makes a change to a setting.

Usually this is when you have a LDB or minimap button that can change the options based on user input. Instead of opening AceConfig and presenting the Interface\AddOns\MyAddOn config screen, the LDB or button gives you a menu.

When the user selects a choice from the menu, then you call NotifyChange(MyAddOn) to keep the two option access methods in sync.
  Reply With Quote
02-01-18, 01:32 PM   #9
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
That makes sense; thanks for the clarification. So if my code does something that adds new controls to my config panel, I have to reload the UI, correct?
  Reply With Quote
02-01-18, 06:45 PM   #10
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Sweetsour View Post
That makes sense; thanks for the clarification. So if my code does something that adds new controls to my config panel, I have to reload the UI, correct?
Yes. Each time you modify a Lua file you need to reload the UI. If you add or remove a Lua file, you need to completely exit out of the game to make that effective.

I never write XML, but I'll assume the same rules apply.
  Reply With Quote
02-01-18, 10:20 PM   #11
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Sweetsour View Post
So if my code does something that adds new controls to my config panel, I have to reload the UI, correct?
No.

Since the code you've provided is incomplete we are left to guess what is going wrong. Based on what has been provided this code should throw an error:
Code:
local function RefreshConfig()
    foreach(LibStub("AceConfigRegistry-3.0").tables,function(k,v)
        ACFG:NotifyChange(k)
    end)
end
That function should look like:
Code:
local function RefreshConfig()
    local ACR = LibStub("AceConfigRegistry-3.0")
    for k, v in pairs(ACR.tables) do
        ACR:NotifyChange(k)
    end
end
But even that is overkill since you are trying to refresh every registered set of options. Something more along the lines of this is what you are going for:
Code:
local optionsSubTables = {
    ["Quick Toggle"] = GetToggleOptions,
    ["Spell Sounds"] = GetSpellOptions,
    ["Defense Sounds"] = GetDefenseOptions,
    ["Combat Sounds"] = GetCombatOptions,
    ["Loot Sounds"] = GetLootOptions,
    ["Chat Sounds"] = GetChatOptions,
    ["Movement Sounds"] = GetMoveOptions,
    ["Backup Sounds"] = GetBackupOptions,
    ["Restore Sounds"] = GetRestoreOptions,
    ["Profiles"] = false
}

local function RefreshConfig()
    local ACR = LibStub("AceConfigRegistry-3.0")
    for name in pairs(optionsSubTables) do
        ACR:NotifyChange(("CustomAudio %s"):format(name))
    end
end

function Ace3:OnProfileUpdate(event,db,profileKey)
    SCA.profile = self.db.profile
    RefreshConfig()
end

function Ace3:OnInitialize()    -- Event: ADDON_LOADED
    local about_panel = LibStub("LibAboutPanel", true)
 
    if about_panel then
        self.optionsFrame = about_panel.new(nil, "CustomAudio")
    end
 
    self.db = LibStub("AceDB-3.0"):New("SCA_db", SCA.defaults)
    SCA.profile = self.db.profile
 
    self.db.RegisterCallback(self, "OnNewProfile", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileReset", "OnProfileUpdate")
 
    -- Setup Options
    local ACD, ACR = LibStub("AceConfigDialog-3.0"), LibStub("AceConfigRegistry-3.0")
    for name, options in pairs(optionsSubTables) do
        local appName = ("CustomAudio %s"):format(name)
        ACR:RegisterOptionsTable(appName, options or LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db, true))
        ACD:AddToBlizOptions(appName, name, "CustomAudio")
    end
end
If you don't have an alternate way to change profiles (i.e. slash command or plugin menu) you could potentially shrink that more to:
Code:
local optionsSubTables = {
    ["Quick Toggle"] = GetToggleOptions,
    ["Spell Sounds"] = GetSpellOptions,
    ["Defense Sounds"] = GetDefenseOptions,
    ["Combat Sounds"] = GetCombatOptions,
    ["Loot Sounds"] = GetLootOptions,
    ["Chat Sounds"] = GetChatOptions,
    ["Movement Sounds"] = GetMoveOptions,
    ["Backup Sounds"] = GetBackupOptions,
    ["Restore Sounds"] = GetRestoreOptions,
    ["Profiles"] = false
}

function Ace3:OnProfileUpdate(event,db,profileKey)
    SCA.profile = self.db.profile
end

function Ace3:OnInitialize()    -- Event: ADDON_LOADED
    local about_panel = LibStub("LibAboutPanel", true)
 
    if about_panel then
        self.optionsFrame = about_panel.new(nil, "CustomAudio")
    end
 
    self.db = LibStub("AceDB-3.0"):New("SCA_db", SCA.defaults)
    SCA.profile = self.db.profile
 
    self.db.RegisterCallback(self, "OnNewProfile", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileUpdate")
    self.db.RegisterCallback(self, "OnProfileReset", "OnProfileUpdate")
 
    -- Setup Options
    local ACD, ACR = LibStub("AceConfigDialog-3.0"), LibStub("AceConfigRegistry-3.0")
    for name, options in pairs(optionsSubTables) do
        local appName = ("CustomAudio %s"):format(name)
        ACR:RegisterOptionsTable(appName, options or LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db, true))
        ACD:AddToBlizOptions(appName, name, "CustomAudio")
    end
end
However, since you didn't post all of your code that can't be tested and your problem may be in unposted code.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » AceConfigRegistry's NotifyChange()

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