WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   AceDB get defalut values? (https://www.wowinterface.com/forums/showthread.php?t=58120)

MickeyPickey 07-23-20 04:04 PM

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)

Rilgamon 07-23-20 10:24 PM

You could iterate over your local Defaults variable?

sezz 07-24-20 03:13 AM

Quote:

Originally Posted by MickeyPickey (Post 336446)
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


All times are GMT -6. The time now is 10:50 AM.

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