Saved Variables
Hey guys, again I'm looking for a little guidance and/or a point in the right direction. I'm always very willing to put the work in and read and learn so a simple pointer to a tutorial etc would be great as well.
I've got to the stage now with my addon where I'd like to start saving variables to disk so that settings will be set between sessions. Could someone possibly take out a few mins to write a short list of what needs to be done. I think I need the logical order of things so that I can try to get it right in my head; I always find that that makes it easier for me to absorb the information. PS: A big thank you to the authors who have been kind enough to answer my previous questions. Aanson. |
All variables that you want to save must be named in you .TOC file under the SavedVariables section
Toc file info: http://www.wowwiki.com/TOC_format Blizzard saves the settings in a lua file with you addon name in the WTF folder. Quote:
There is a few events to tell you when this has happened. It will be done loading when ADDON_LOADED has fired. I suggest using a table and save settings inside the table like keys. That way you minimize what you need to change when you add more settings or even remove them. maybe something like this. just a suggestion, but its not needed. Lua Code:
there are also some libraries (ace?) to do this for you. |
Saved Variables are first defined in the TOC file. This tells WoW which globals to save for your addon when the user logs out.
TOC: Code:
## SavedVariables: Global_Name |
Quote:
Here is the simple system I use for managing default settings in my addons: In MyAddon.toc: Code:
## SavedVariables: MyAddonDB Code:
-- This function gets run when the PLAYER_LOGIN event fires: |
Quote:
of would this function replace your: Code:
local cfg = MyAddonDB.defaults Thanks Coke |
Please don't quote an entire 100+ line post, especially if it's the last post in the thread. :(
Quote:
Code:
local defaults = { Code:
local defaults = { Also, this thread is very old. I suggest you check this more current one instead: http://forums.wowace.com/showthread.php?t=21864 |
Thank You Phanx for all you knowledge and wisdom with wow and lua.
Coke |
I know this thread is pretty old, but i would like to correct a major error with Phanx'es code, which is probably just a typo:
Lua Code:
If the not is not there it will auto reset your settings to the default one every time you log in. |
Quote:
Code:
if type(dst) ~= "table" then dst = { } end |
Quote:
But of course the ~= "table" checker could be better. |
No, that returns "nil".
|
Quote:
|
All times are GMT -6. The time now is 10:18 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI