Thread Tools Display Modes
08-26-16, 05:34 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Ace3 DB not initializing?

After following the various documentation and tutorials on wowace.com, I can't seem to get default values to appear in my saved variables file on a fresh file. This is my code.

Lua Code:
  1. function Auras:OnInitialize()
  2.     local defaults = {
  3.         char = {
  4.             cooldowns = {},
  5.             info = {
  6.                 totems = {
  7.                     eShield = {
  8.                     },
  9.                     cBurst = {
  10.                         absorb = 0;
  11.                     }
  12.                 }
  13.             },
  14.             aura = {
  15.                 minor = {
  16.                     [0] = {
  17.                         WindShear = true,
  18.                         Hex = true,
  19.                     },
  20.                     [1] = {
  21.                         Thunderstorm = true,
  22.                         EarthElemental = true,
  23.                         FireElemental = true,
  24.                         FlameShock = true,
  25.                         EarthShock = true,
  26.                         LavaBurst = true,
  27.                        
  28.                     },
  29.                     [2] = {
  30.                    
  31.                     },
  32.                     [3] = {
  33.                    
  34.                     },
  35.                 },
  36.             },
  37.         }
  38.     }
  39.  
  40.     self.db = LibStub("AceDB-3.0"):New("SSA_db",defaults);
  41. end

But this is all that shows up in my saved variables file:

Lua Code:
  1. SSA_db = {
  2.     ["profileKeys"] = {
  3.         ["Sweetsour - Firetree"] = "Sweetsour - Firetree",
  4.     },
  5. }
  Reply With Quote
08-26-16, 05:41 PM   #2
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Hmm, odd. The file shows nothing, but /dump SSA_db shows everything. Yet, a checkbox I'm trying to set to checked/unchecked on load based on the DB values isn't firing.
  Reply With Quote
08-26-16, 06:28 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
After working through it, I discovered that I wasn't creating my objects in the correct order.
  Reply With Quote
08-26-16, 06:30 PM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
AceDB doesn't write to file the values that are equal to the defaults, so if you've changed nothing there might not be anything in the file. Although the char table might be there...

Can you show some more code? I don't know when OnInitialize is being called, nor where you are trying to setup the checkbox, so it's impossible to say whether this is intended or no.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
08-26-16, 06:58 PM   #5
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
.TOC file
Lua Code:
  1. ## Interface: 70000
  2. ## Title: <title>
  3. ## Notes:<desc>
  4. ## Author: Sweetsour
  5. ## Version: @project-version@
  6. ## SavedVariables: SSA_db
  7. ## X-Curse-Packaged-Version: r1
  8. ## X-Curse-Project-Name:<title>
  9. ## X-Curse-Project-ID: <title>
  10. ## X-Curse-Repository-ID: wow/<title>/mainline
  11.  
  12. ## OptionalDeps: Ace3, LibStub
  13.  
  14. #@no-lib-strip@
  15. Libs\LibStub\LibStub.lua
  16. Libs\CallbackHander-1.0\CallbackHander-1.0.lua
  17. Libs\AceAddon-3.0\AceAddon-3.0.xml
  18. Libs\AceGUI-3.0\AceGUI-3.0.xml
  19. Libs\AceHook-3.0\AceHook-3.0.xml
  20. Libs\AceConfig-3.0\AceConfig-3.0.xml
  21. Libs\AceDB-3.0\AceDB-3.0.xml
  22. Libs\AceEvent-3.0\AceEvent-3.0.xml
  23. Libs\AceLocale-3.0\AceLocale-3.0.xml
  24. Libs\AceTimer-3.0\AceTimer-3.0.xml
  25. #@end-no-lib-strip@
  26. Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
  27.  
  28. embeds.xml
  29.  
  30. Locales\LocalizationCore.lua
  31. Locales\enUS.lua
  32. Locales\ptBR.lua
  33. Locales\frFR.lua
  34. Locales\deDE.lua
  35. Locales\itIT.lua
  36. Locales\koKR.lua
  37. Locales\esMX.lua
  38. Locales\ruRU.lua
  39. Locales\zhCN.lua
  40. Locales\esES.lua
  41. Locales\zhTW.lua
  42.  
  43. SA_Core.lua
  44. SA_Config.lua

Core File
Lua Code:
  1. local FOLDER_NAME, SSA = ...
  2.  
  3. local Auras = LibStub("AceAddon-3.0"):NewAddon(FOLDER_NAME, "AceEvent-3.0", "AceHook-3.0", "AceTimer-3.0");
  4. Auras.version = GetAddOnMetadata(FOLDER_NAME, "Version")
  5.  
  6. local L = LibStub("AceLocale-3.0"):GetLocale(FOLDER_NAME, true)
  7.  
  8. function Auras:OnInitialize()
  9.     local defaults = {
  10.         char = {
  11.             cooldowns = {},
  12.             info = {
  13.                 totems = {
  14.                     eShield = {
  15.                     },
  16.                     cBurst = {
  17.                         absorb = 0;
  18.                     }
  19.                 }
  20.             },
  21.             aura = {
  22.                 minor = {
  23.                     [0] = {
  24.                         WindShear = true,
  25.                         Hex = true,
  26.                     },
  27.                     [1] = {
  28.                         Thunderstorm = true,
  29.                         EarthElemental = true,
  30.                         FireElemental = true,
  31.                         FlameShock = true,
  32.                         EarthShock = true,
  33.                         LavaBurst = true,
  34.                     },
  35.                     [2] = {
  36.                     },
  37.                     [3] = {
  38.                     },
  39.                 },
  40.             },
  41.         }
  42.     }
  43.  
  44.     self.db = LibStub("AceDB-3.0"):New("SSA_db",defaults);
  45. end

Config File
Lua Code:
  1. local FOLDER_NAME, SSA = ...
  2. local version = GetAddOnMetadata(FOLDER_NAME,"Version");
  3. local L = LibStub("AceLocale-3.0"):GetLocale(FOLDER_NAME, true)
  4. local Auras = LibStub("AceAddon-3.0"):GetAddon(FOLDER_NAME)
  5. local AceGUI = LibStub("AceGUI-3.0");
  6. SSA.widgets = {
  7.     checkbox = {
  8.         minor = {
  9.             [0] = {
  10.             },
  11.             [1] = {
  12.             },
  13.             [2] = {
  14.             },
  15.             [3] = {
  16.             }
  17.         },
  18.         major = {
  19.             [0] = {
  20.             },
  21.             [1] = {
  22.             },
  23.             [2] = {
  24.             },
  25.             [3] = {
  26.             }
  27.         }
  28.     },
  29. };
  30. local f = AceGUI:Create("Frame");
  31. f:SetCallback("OnClose",function(widget) AceGUI:Release(widget) end);
  32. f:SetLayout("Fill");
  33.  
  34. local function DrawGroup1(container)
  35.     -- Under Construction
  36. end
  37.  
  38. local function DrawGroup2(container)
  39.     local MinorAuraGrp = AceGUI:Create("InlineGroup");
  40.     MinorAuraGrp:SetWidth(200);
  41.     MinorAuraGrp:SetHeight(200);
  42.     MinorAuraGrp:SetTitle(L["MinorAuras"]);
  43.     MinorAuraGrp:SetLayout("Fill");
  44.     container:AddChild(MinorAuraGrp);
  45.    
  46.     local MajorAuraGrp = AceGUI:Create("InlineGroup");
  47.     MajorAuraGrp:SetWidth(400);
  48.     MajorAuraGrp:SetHeight(200);
  49.     MajorAuraGrp:SetTitle(L["MajorAuras"]);
  50.     MajorAuraGrp:SetLayout("Fill");
  51.     container:AddChild(MajorAuraGrp);
  52.    
  53.     local checkbox = AceGUI:Create("CheckBox");
  54.     checkbox:SetType("checkbox");
  55.     checkbox:SetLabel(" "..L["Thunderstorm"]);
  56.     checkbox:SetCallback("OnValueChanged",function(self,event,value)
  57.         if (value) then
  58.             Auras.db.char.aura['minor'][1].Thunderstorm = true;
  59.             SSA.Thunderstorm:Show();
  60.         else
  61.             Auras.db.char.aura['minor'][1].Thunderstorm = false;
  62.             SSA.Thunderstorm:Hide();
  63.         end
  64.     end);
  65.     SSA.widgets.checkbox['minor'][1][51490] = checkbox;
  66.     MinorAuraGrp:AddChild(checkbox);
  67.    
  68.     local checkbox = AceGUI:Create("CheckBox");
  69.     checkbox:SetType("checkbox");
  70.     checkbox:SetLabel(" "..L["EarthElemental"]);
  71.     checkbox:SetPoint("TOPLEFT",3,-13);
  72.     checkbox:SetCallback("OnValueChanged",function(self,event,value)
  73.         if (value) then
  74.             Auras.db.char.aura['minor'][1].EarthElemental = true;
  75.             SSA.EarthElemental:Show();
  76.         else
  77.             Auras.db.char.aura['minor'][1].EarthElemental = false;
  78.             SSA.EarthElemental:Hide();
  79.         end
  80.     end);
  81.     SSA.widgets.checkbox['minor'][1][198103] = checkbox;
  82.     MinorAuraGrp:AddChild(checkbox);
  83. end
  84.  
  85. local function DrawGroup3(container)
  86.     -- Under Construction
  87. end
  88.  
  89. local function DrawGroup4(container)
  90.     -- Under Construction
  91. end
  92.  
  93. local function SelectGroup(container, event, group)
  94.     container:ReleaseChildren()
  95.     if group == "tab1" then
  96.         DrawGroup1(container)
  97.     elseif group == "tab2" then
  98.         DrawGroup2(container)
  99.     elseif group == "tab3" then
  100.         DrawGroup3(container)
  101.     elseif group == "tab4" then
  102.         DrawGroup4(container)
  103.     end
  104. end
  105.  
  106. local tab =  AceGUI:Create("TabGroup");
  107. tab:SetLayout("Flow");
  108. tab:SetTabs({{text="Shared",value="tab1"},{text="Elemental", value="tab2"}, {text="Enhancement", value="tab3"}, {text="Restoration",value="tab4"}});
  109. tab:SetCallback("OnGroupSelected", SelectGroup);
  110. tab:SelectTab("tab1")
  111.  
  112. f:AddChild(tab)

I should add that the second object I create in "DrawGroup2" (EartElemental) is being placed outside of the UI that I'm trying to place it in. The first object I create (Thunderstorm) is being placed in the UI group fine.

EDIT: Changing the group's layout to "Flow" seemed to have worked, but it doesn't look like I can control the size of the group now =/

Last edited by Sweetsour : 08-26-16 at 07:07 PM.
  Reply With Quote
08-26-16, 08:44 PM   #6
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Just updating to let you [all] know that I've switched to AceConfig. Took some time to learn the basics, but I'm definitely finding it easier.
  Reply With Quote
08-26-16, 09:01 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860


AceConfig is not a replacement/alternative for AceDB...

AceConfig handles the **display** of your options.
AceDB handles the **storage** of your saved variables.
__________________
"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
08-26-16, 09:13 PM   #8
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Seerah View Post


AceConfig is not a replacement/alternative for AceDB...

AceConfig handles the **display** of your options.
AceDB handles the **storage** of your saved variables.
Right, sorry. I was having issues trying to get AceGUI and my AceDB to work together, and the setup of the UI itself seemed tedious. I'm finding it a lot easier to set everything up with AceConfig
  Reply With Quote
08-28-16, 10:55 PM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
This line should be in OnInitialize, and not in your defaults table. Here is the Ace3 tutorial.
Code:
self.db = LibStub("AceDB-3.0"):New("SSA_db", defaults)
  Reply With Quote
08-29-16, 05:02 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
This line should be in OnInitialize, and not in your defaults table. Here is the Ace3 tutorial.
Code:
self.db = LibStub("AceDB-3.0"):New("SSA_db", defaults)
I'm not sure what you're talking about -- that line is in the OnInitialize function (from OP's last post) and is not inside the "defaults" table.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-30-16, 04:17 AM   #11
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Phanx View Post
I'm not sure what you're talking about -- that line is in the OnInitialize function (from OP's last post) and is not inside the "defaults" table.
It was inside the defaults table when I looked. If the OP has fixed that, then great
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Ace3 DB not initializing?


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