Quantcast ACE3 DB default values - WoWInterface
Thread Tools Display Modes
01-05-20, 04:26 AM   #1
KingBoo
A Defias Bandit
Join Date: Jan 2020
Posts: 2
Question ACE3 DB default values

Hi,
i am the developer of a small ACE3 addon named RaidSummon (WoW Classic).
I have a set of default ACE3 DB values (the "keywords" table). If i delete all of them and reload the UI they will get populated again with the default values. I want to be able to save them in an empty state. Also if I delete them entry by entry and add new ones - after a reload - they will still be there.

Any ideas how to fix this?

Code: https://github.com/isitLoVe/RaidSumm...RaidSummon.lua

Steps to reproduce:
start WoW
default table with 3 entries will be loaded
add one new entry via /rs config
delete the default 3 entries
reload the ui
the 3 default entries are still there + the new one
  Reply With Quote
01-05-20, 08:02 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,101
Ace3 (not ACE3, it isn't an acronym) via AceDB only saves changes if the user actually makes a change. Say you have a default of "pet" = "dog". You will see nothing in the SV file for that entry. Should the user change "pet" = "cat" then you will see MyAddOnDB.profile.pet = "cat" in the SV file.

Changing the contents of the default table on the fly won't always change because the previous data is still in memory, as you discovered. You might have to completely exit the game to test. You can add to the table and reload, but removing entries from the table might not work as intended without a complete restart.

What do you mean by an "empty state"? And in your OnItialize() function you specify RaidSummonSyncDB = {} on top of self.db = LibStub("AceDB-3.0"):New("RaidSummonOptionsDB", defaults, true). Why are you setting up two saved variables, one without AceDB? For that matter, line 223 tells the addon to wipe RaidSummonSyncDB each time it is loaded.
  Reply With Quote
01-05-20, 08:08 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,101
Side note, line 1 should begin with the word local and optionsProfile on line 209 should also be localized.

If you have multiple Lua files in your addon, you can get a reference to the main table in the other Lua files using
Code:
local RaidSummon = LibStub("AceAddon-3.0"):GetAddon("RaidSummon")
This will cut down on errors caused by name conflicts in the global namespace.
  Reply With Quote
01-05-20, 08:12 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,101
BTW, what are the types for the keywords in your options table? Am I not seeing those entries?
Code:
type = "toggle"
type = "select"
type = "keybind"
etc
  Reply With Quote
01-06-20, 03:14 AM   #5
KingBoo
A Defias Bandit
Join Date: Jan 2020
Posts: 2
Say you have a default of "pet" = "dog". You will see nothing in the SV file for that entry. Should the user change "pet" = "cat" then you will see MyAddOnDB.profile.pet = "cat" in the SV file.
Currently i am using the format ["regex value"] = true format to store data. I know that default values wont appear in the SV file.

What do you mean by an "empty state"? And in your OnItialize() function you specify RaidSummonSyncDB = {} on top of self.db = LibStub("AceDB-3.0"):New("RaidSummonOptionsDB", defaults, true). Why are you setting up two saved variables, one without AceDB? For that matter, line 223 tells the addon to wipe RaidSummonSyncDB each time it is loaded.
Empty state is when the user deletes all default values. When he does that, after a reload or restart of WoW the table will have the default values again (instead of no values at all). I need some options to allow storing keys that are empty like creating a new variable "keywordsareemptybyuserdecision". But that would be only a workaround.

Side note, line 1 should begin with the word local and optionsProfile on line 209 should also be localized.
Will do that in the next update, thanks for the tip.

BTW, what are the types for the keywords in your options table? Am I not seeing those entries?
I am using the standard Ace3 types like execute, toggle, select and input. Starting at line 5.

I only want to store data in the variable RaidSummonOptionsDB in the SV file. No need to store RaidSummonSyncDB.
  Reply With Quote
01-06-20, 02:21 PM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,101
Ah. I'll poke into this deeper later. Looking at your code and your answers above, here's another tip: if you want to reset or wipe RaidSummonSyncDB such as you do on line 255, I instead suggest you use the wipe() function. It is faster and more accurate than telling Lua to recreate the variable. This is because, using your method, Lua has to first look through the table RaidSummonSyncDB, determine if there are values, nil them, then build the table all over again. wipe() skips right to the nil step, and doesn't bother with steps 1 or 3 because it doesn't need to do those.
Code:
wipe(RaidSummonSyncDB)
Alternately you can use a for loop rather than wipe(). If RaidSummonSyncDB contains lots and lots of data, using for can be faster. I have heard for is faster on small tables as well; your results may vary. Always test!
Code:
for i = 1, #RaidSummonSyncDB do
    RaidSummonSyncDB[i] = nil
end
You still have access to RaidSummonSyncDB later; it is empty, not deleted.

I am also curious about lines 219 - 230. Are you intentionally creating global variables? Do they need to be global? Can those be defined as local?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » ACE3 DB default values

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