WoWInterface - View Single Post - Defaults "These Settings" handle
View Single Post
07-29-16, 07:00 PM   #2
A Molten Giant
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 931
Originally Posted by Benio View Post
Lua Code:
  1. ADDON_NAME.frames.options.default = function(...)
  2.     ADDON_NAME.db = ADDON_NAME.default;
  3.     ADDON_NAME.libs.ConfigRegistry:NotifyChange("ADDON_NAME");
  4. end;

It changes ADDON_NAME.db, and corresponding GUI in options panel at will.
However, it works only first time after (re)loading GUI and changes are not saved.

Problem: How to handle Defaults → "These Settings" to default it's settings and save them correctly?

Tables are passed by reference, what you're doing is just making ADDON_NAME.db point to ADDON_NAME.default instead of copying the table

So anything you do afterwards is with the table referenced in ADDON_NAME.default instead of the dereferenced one from ADDON_NAME.db

If you're lazy you can use Blizzard's CopyTable for deep copying
Lua Code:
  1. function CopyTable(settings)
  2.     local copy = {};
  3.     for k, v in pairs(settings) do
  4.         if ( type(v) == "table" ) then
  5.             copy[k] = CopyTable(v);
  6.         else
  7.             copy[k] = v;
  8.         end
  9.     end
  10.     return copy;
  11. end
ADDON_NAME.db = CopyTable(ADDON_NAME.default)

But there also was something about AceDB tables being "magic" tables
So in that specific case I'm probably wrong, and I don't really understand that part anymore


(Edit) would DBObjectLib:ResetProfile() work for you?

Last edited by Ketho : 07-29-16 at 07:32 PM.
  Reply With Quote