WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   ACE3 DB default values (https://www.wowinterface.com/forums/showthread.php?t=57762)

KingBoo 01-05-20 04:26 AM

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

myrroddin 01-05-20 08:02 AM

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.

myrroddin 01-05-20 08:08 AM

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.

myrroddin 01-05-20 08:12 AM

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


KingBoo 01-06-20 03:14 AM

Quote:

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.

Quote:

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.

Quote:

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.

Quote:

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.

myrroddin 01-06-20 02:21 PM

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?


All times are GMT -6. The time now is 02:54 AM.

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