Quantcast SavedVariables and portable settings - WoWInterface
Thread Tools Display Modes
03-25-15, 03:01 PM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
SavedVariables and portable settings

Hello, I was just wondering if there's any conventional way of importing saved variables from another character, other than keeping a matrix with realms and toons and loading the whole damn table each time?

I want to keep my memory usage to a minimum, and while loading a couple of strings isn't that demanding, I store more than a handful of strings on each character. I want to avoid having to read from a gigantic table if I can avoid it.
__________________
  Reply With Quote
03-25-15, 05:31 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
I wouldn't really worry about this. Variables gets loaded into the memory when you login into the game and/or reload your UI, and it's getting saved when you log out of the game. Also it doesn't really matter how big is the table when you are searching in it since you probably will only searcing in the current profiles subtable. And when you just want to import a profile you just overwrite the current profile table with the selected one.
  Reply With Quote
03-25-15, 05:46 PM   #3
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
Do you think it would be a good approach to store two identical tables? As in one table that is character specific and one subtable in a large table for all characters?

Let's say the memory load is minimal. I still don't like the idea of players having to remove all settings on all characters if the account-wide table becomes corrupted. So the only purpose of the account-wide table would be to store settings for import/export.

What is the most common approach to this?
__________________
  Reply With Quote
03-25-15, 05:57 PM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
Could work, but it could create more trouble then it would solve.

You can dodge most of the saved variable corruption with this method (written by Phanx):

Lua Code:
  1. local defaultSettings = {
  2.     ["profiles"] = {
  3.         ["Default"] = {
  4.             ["options"] = {
  5.                 ["width"] = 400,
  6.                 ["height"] = 600,
  7.                 ["scale"] = 1,
  8.             },
  9.             ["frames"] = {
  10.  
  11.             },
  12.         },
  13.     },
  14.     ["profileKeys"] = {
  15.  
  16.     },
  17. }
  18.  
  19. local function UpgradeVariables(src, dst)
  20.     if type(src) ~= "table" then
  21.         return { }
  22.     end
  23.     if type(dst) then
  24.         dst = { }
  25.     end
  26.     for k, v in pairs(src) do
  27.         if type(v) == "table" then
  28.             dst[k] = UpgradeVariables(v, dst[k])
  29.         elseif type(v) ~= type(dst[k]) then
  30.             dst[k] = v
  31.         end
  32.     end
  33.     return dst
  34. end
  35.  
  36. MyAddonDB = UpgradeVariables(defaultSettings, MyAddonDB)

This way if the user manages to overwrite the ["scale"] with a string, then it would reset to it's default value on load.

It's also good if you let say in a new version you want to replace the ["width"] and ["height"] values with ["size"] = 600, then it's gonna create this variable on load, to prevent nil errors for users with an older saved variables.

But i would say for multi-profile addons with import and export settings the more common way is to use the account-wide variables only.

Last edited by Resike : 03-25-15 at 06:08 PM.
  Reply With Quote
03-25-15, 06:47 PM   #5
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
I also dislike having a general saved variable with the data from all characters being loaded all the time. What may work (I thought about it but never really implemented) you can make a secondary addon (a lot of addons have subaddons so not a big deal) that would be enabled when the user want to export/import and once it is done it would be disabled again.
1) user enable module
2) user log on the char with data to export
3) char saved variables are copied in the general saved variables
4) user log on the char with data to import
5) data from general saved variables are copied into the current char saved variables
6) user disable the module

This would work if the import/export is very rare. If not then it would be very annoying disabling/enable the module and logging into another toons.
  Reply With Quote
03-25-15, 06:51 PM   #6
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
I'm afraid the stuff I'm importing is button maps, bindings and mouse settings so it's very likely it will be used often. Now, another question pertaining to the same thing:

Having registered the event PLAYER_LOGOUT, I can't seem to store the subtable on logout. It's as if my frame never even receives the event. Calling the function manually stores the table just fine. Any ideas why this is happening?
__________________
  Reply With Quote
03-25-15, 06:56 PM   #7
Banknorris
A Chromatic Dragonspawn
 
Banknorris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 153
I use this techinique:
Lua Code:
  1. local function OnLogoutStuff()
  2.     --logout stuff here
  3. end
  4.  
  5. local Original_Logout = Logout
  6. function Logout()
  7.     OnLogoutStuff()
  8.     return Original_Logout()
  9. end
  10.  
  11. local Original_Quit = Quit
  12. function Quit()
  13.     OnLogoutStuff()
  14.     return Original_Quit()
  15. end
  16.  
  17. local Original_ReloadUI = ReloadUI
  18. function ReloadUI()
  19.     OnLogoutStuff()
  20.     return Original_ReloadUI()
  21. end
  22.  
  23. local Original_ConsoleExec = ConsoleExec
  24. function ConsoleExec(msg)
  25.     if msg=="reloadui" then
  26.         OnLogoutStuff()
  27.     end
  28.     return Original_ConsoleExec(msg)
  29. end

Last edited by Banknorris : 03-25-15 at 07:03 PM.
  Reply With Quote
03-25-15, 07:11 PM   #8
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
Lol. So you really have to hook the actual functions? Why does that event even exist then?
__________________
  Reply With Quote
03-25-15, 07:26 PM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
Not sure why do you need the logout event. The client should automatically dump your current saved variables from the memory to the hard drive on logout. And thoose saved values gonna get loaded into the memory on the next login.
  Reply With Quote
03-25-15, 07:27 PM   #10
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
The reason I want to do this is because I want to duplicate the table and store them in the account-wide saved variable for import on other characters. I want to do it on logout to ensure the duplicated table is up to date. Eventually I might remove the character specific variables, but my addon is riddled with bugs and at the moment I think this is the best approach.
__________________

Last edited by MunkDev : 03-25-15 at 07:31 PM.
  Reply With Quote
03-26-15, 02:38 AM   #11
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
This is ridiculous, nobody wants to enable a secondary addon to import settings from another character because you don't want to store what is likely less than a megabyte of data in an account-wide table.

You could do exactly the same thing by just having an empty account-wide table in your addon purely for storing what you intend to import on another character.

But you should ask yourself whether this functionality is even necessary; most players use account-wide bindings, and the people who don't could probably live with importing from the last character they were logged into or a generic template, rather than picking from their entire list of characters to copy from.

Last edited by semlar : 03-26-15 at 04:48 AM.
  Reply With Quote
03-26-15, 05:21 AM   #12
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by semlar View Post
This is ridiculous, nobody wants to enable a secondary addon to import settings from another character because you don't want to store what is likely less than a megabyte of data in an account-wide table.
Sounds like a common case of Overengineering.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
03-26-15, 08:41 PM   #13
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
Originally Posted by Torhal View Post
Sounds like a common case of Overengineering.
Reminded me of this.
Originally Posted by semlar View Post
This is ridiculous, nobody wants to enable a secondary addon to import settings from another character because you don't want to store what is likely less than a megabyte of data in an account-wide table.
This was not a solution I considered for even a moment.
Originally Posted by semlar View Post
You could do exactly the same thing by just having an empty account-wide table in your addon purely for storing what you intend to import on another character.
Yes. That's pretty much what's going on. Copying the character specific table also allows a proper backup that you can fall back on if you mess up or in any way trash your settings. A character can import its own bindings, which will load the table from their previous game session.
Originally Posted by semlar View Post
But you should ask yourself whether this functionality is even necessary; most players use account-wide bindings, and the people who don't could probably live with importing from the last character they were logged into or a generic template, rather than picking from their entire list of characters to copy from.
I have a default setup that loads automatically. Saving generic templates would be an idea that I might look into.
Also, the bindings I'm talking about are not bindings in the traditional sense:



For the record I went with the approach of storing a character specific table and then dumping that into the account-wide table on logout. This gives both a chance to reset bindings to an earlier stage and allows for importing bindings on other characters.
__________________

Last edited by MunkDev : 03-26-15 at 08:46 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SavedVariables and portable settings

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