WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SavedVariables saving (https://www.wowinterface.com/forums/showthread.php?t=55981)

gempir 01-18-18 04:04 PM

SavedVariables saving
 
Hey guys,

I'm having issues with Saved Variables. I'm writing a config menu for my Addon with the help of Ace3. I really have no issues with Ace3 currently and I'm pretty happy about but i think I'm misunderstanding saved variables somehow.

I have a few of these functions (4 in total)

Lua Code:
  1. function G.ace:GetAutoRepair()
  2.     return self.db.profile.autoRepair
  3. end
  4.  
  5. function G.ace:SetAutoRepair(info, input)
  6.     self.db.profile.autoRepair = input
  7. end

The db defined is like this:

Lua Code:
  1. self.db = LibStub("AceDB-3.0"):New("gempDB", defaults, true)

gempDB is in my Toc file like this
Code:

## SavedVariables: gempDB
But I can't get the variables to save correctly. Saving and reloading just resets the option to the previous state. Same with logout. I tried Logout, deleting the saved vars file for my addon and logging back in. Then It has weird defaults that I never set anywhere which are different from my default table.
And they are even different from the options that show up in the ingame menu. Changing ingame options again doesn't change anything in the saved vars file...

At the beginning some options didn't even show up in the saved vars file. Only after copy pasting them in, deleting it, restarting the game they showed up at some point.

This is my saved vars file currently so it looks like Ace3 is doing something atleast.

Lua Code:
  1. gempDB = {
  2.     ["profileKeys"] = {
  3.         ["Wraths - Proudmoore"] = "Wraths - Proudmoore",
  4.     },
  5.     ["profiles"] = {
  6.         ["Wraths - Proudmoore"] = {
  7.             ["autoRepair"] = false,
  8.             ["hideErrors"] = "always",
  9.             ["allEnemyDebuffs"] = false,
  10.             ["sellJunk"] = false,
  11.         },
  12.     },
  13. }

Could someone give me a short explanation how saved variables exactly work and how I should work with them while developing an addon.
Like when are they saved to file? Does reloading break saved vars or something? What are the defaults? etc...

Seerah 01-18-18 04:45 PM

Saved variables are written to file at the end of a session - so at reload or logout. (Just an FYI, if your client crashes then saved variables will not be written.)

(Another FYI...) For a simple addon with simple saved variables, AceDB is overkill and it's TONS easier to just use the built in system. AceDB was written to handle profiles. Some authors still prefer to create their own profile system rather than use AceDB, though this isn't because there's anything wrong with it - just that it's not necessary to use unless you want to.

All that said, AceDB does not save any data if it is unchanged from the default values.

Give this a look over: https://wow.gamepedia.com/Saving_var..._game_sessions

gempir 01-18-18 04:55 PM

Thanks but I've really got something more complicated on my hands. I will have to handle multiple pages of settings. I was writing my own options but realized quickly that it's a lot of effort.

Seerah 01-18-18 05:00 PM

You aren't required to use AceDB to use AceConfig. Just use it if you want to or feel you need its features.

(Most of my addons use AceConfig, none of my addons use AceDB.)

gempir 01-18-18 06:50 PM

Ok yeah true. But I have little experience with AceConfig and the tutorials are pretty straightforward with AceDB.

AceDB doesn't seem to be the problem even, probably just me being stupid.

Edit:

So after removing AceDB, Settings/Vars save fine, I'm not sure where I went wrong with AceDB. I'd actually like to use AceDB because profiles could be very useful for my addon. If anyone has any input, I'm thankful.

Here is the relevant code: https://github.com/gempir/gempUI/blo.../config.lua#L3

I've added a Menu for setting profiles which looks nice but changing profile and reloading just resets to Default again.
It seems AceDB can't write into saved vars for some reason.


I also have another question:

When do i load saved vars? I currently have a callback function that fire when they are loaded and then executes whatever you pass it. But how do I scale that efficently. I have stuff like actionbars which require a length or so given, so should I wait even initalizing those bars until the saved vars are loaded?

myrroddin 01-20-18 06:22 AM

Quote:

Originally Posted by gempir (Post 326553)
When do i load saved vars?

Ace3 loads your SVs for you during OnInitialize; you don't need to load them yourself, unless I am misunderstanding the question.

gempir 01-20-18 06:44 AM

Quote:

Originally Posted by myrroddin (Post 326555)
Ace3 loads your SVs for you during OnInitialize; you don't need to load them yourself, unless I am misunderstanding the question.

Yeah I get that part. But do I load my entire Interface in OnInitialize? Like I have multiple files doing stuff like oUF unitframes, actionbars, buffs, simple panels, minimap or other stuff. Some of those require settings like how many buttons should actionbar 1 have.

Should I just delay the creation of all frames, objects etc. until I have loaded the saved vars (in OnInitialize) ?

This is more of a general question and has little to do with Ace3

Lombra 01-20-18 09:56 AM

Generally you would create everything immediately and then set it up according to user settings when those become available.

gempir 01-20-18 10:04 AM

Quote:

Originally Posted by Lombra (Post 326560)
Generally you would create everything immediately and then set it up according to user settings when those become available.

Okay so if I have like a frame that should sit in some custom position I would create that frame, give it a background, border etc.

and then I do SetPoint with the coords the user specified in the saved vars.


All times are GMT -6. The time now is 08:04 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI