Thread Tools Display Modes
01-18-18, 04:04 PM   #1
gempir
A Black Drake
 
gempir's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 84
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...
  Reply With Quote
01-18-18, 04:45 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-18-18, 04:55 PM   #3
gempir
A Black Drake
 
gempir's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 84
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.
  Reply With Quote
01-18-18, 05:00 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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.)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-18-18, 06:50 PM   #5
gempir
A Black Drake
 
gempir's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 84
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?

Last edited by gempir : 01-19-18 at 08:41 AM.
  Reply With Quote
01-20-18, 06:22 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by gempir View Post
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.
  Reply With Quote
01-20-18, 06:44 AM   #7
gempir
A Black Drake
 
gempir's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 84
Originally Posted by myrroddin View Post
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
  Reply With Quote
01-20-18, 09:56 AM   #8
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Generally you would create everything immediately and then set it up according to user settings when those become available.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-20-18, 10:04 AM   #9
gempir
A Black Drake
 
gempir's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2015
Posts: 84
Originally Posted by Lombra View Post
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SavedVariables saving

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