Quantcast
AceDB get defalut values? - WoWInterface
Thread Tools Display Modes
07-23-20, 04:04 PM   #1
MickeyPickey
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2020
Posts: 3
AceDB get defalut values?

Hello there! I'm newbie on Lua and Addon writing in general. Now i'm trying to create one simple addon based on Ace3, that handle players tracking spells and switches between them at a certain interval.

For now i'm stucked on one point that i can't access\iterate through the default options values using for-do loop.

For example i have a DB with defaults:

Lua Code:
  1. local defaults = {
  2.   profile  = {
  3.     enable = true,
  4.     trackOnlyWhileMoving = true,
  5.     castInterval = 2,
  6.     type1 = "minerals",
  7.     type2 = "herbs",
  8.     trackingTypes = {
  9.       ['*'] = true
  10.     },
  11.   }
  12. }
  13.  
  14. self.db = LibStub("AceDB-3.0"):New("ResourceAutoTrackerCharDB", defaults, true)

How can i iterate through the
Lua Code:
  1. self.db.profile["trackingTypes"]
to get its keys and values if they in default state (not changed by user, not saved in SV file)?

I found that this way doesn't work for me(
Lua Code:
  1. for key, val in pairs(self.db.profile["trackingTypes"]) do
  2.   print(key, ', ', val)
  3. end

print method returns empty string...

But if i refer directly to the
Lua Code:
  1. self.db.profile["trackingTypes"]["key"]
i can get its default value.


*i hope you understand what i was ment. sorry for my bad eng)

Last edited by MickeyPickey : 07-23-20 at 04:11 PM.
  Reply With Quote
07-23-20, 10:24 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 789
You could iterate over your local Defaults variable?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
07-24-20, 03:13 AM   #3
sezz
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 131
Originally Posted by MickeyPickey View Post
print method returns empty string...

But if i refer directly to the
Lua Code:
  1. self.db.profile["trackingTypes"]["key"]
i can get its default value.
that's the expected result

* is a special key in AceDB that defines the default value (by adding a metatable to trackingTypes), so all your not yet existing trackingTypes return its value (true in your case):

https://www.wowace.com/projects/ace3...rial#title-3-1
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » AceDB get defalut 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