Reply
Thread Tools Display Modes
Unread 11-21-05, 02:51 PM   #1
shouryuu
A Chromatic Dragonspawn
 
shouryuu's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2005
Posts: 150
SavedVariables

Hello everyone, it's your favorite forum troll, Shouryuu!
Well once more I need some help with some code... I've managed to write a neat little add-on but sadly enough, I just cannot manage to save variables bewtween sessions. I've put the table's names in the TOC, saved the TOC, exited the game, reload the game blah blah blah done it all and yet still no variables saved... So I'm looking for a benevolent soul to either try and walk me throught this difficult period, or just take a look at my code (send me a PST if you want the code, I'll send it to you on either mIRC or via e-mail) and see what's wrong!
Thank you very much!
(I'm going to try my luck on the official forums but it's probably going to get drowned in a sea of Nerf Decursive!11one!onoeneoeneleven! threads soooooooo)
shouryuu is offline   Reply With Quote
Unread 11-21-05, 03:06 PM   #2
DSanai
A Wyrmkin Dreamwalker
 
DSanai's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2005
Posts: 50
In the TOC file, you will add a statement like this:

## SavedVariables: YourMod_Data

In your LUA file, you will want to ACCESS the variables by using a table structure based on that base variable, YourMod_Data.

ANYTHING you assign to that table will be saved AUTOMATICALLY by WoW.

Therefore, don't be using a bunch of other variables, but rather access the SV data and save the data to them.

In your VARIABLES_LOADED event handler, you can do this:

if (not YourMod_Data) then YourMod_Data = {}; end

This will initialize the main table, if it doesn't already exist. After that, you need to decide if you want to save the variables by-character or by-server.

local serverName = GetCVar("realmName");
local charName = UnitName("player");
svName = charName.." of "..serverName; -- This should be a persistant variable, either local to the ENTIRE LUA, or global

if (not YourMod_Data[svName]) then YourMod_Data = { -- Set Defaults Here
["show"] = true,
["something"] = 15,
}; end

Any time they change something (such as the "show" variable, above), change it directly:
YourMod_Data[svName]["show"] = false;

And any time you need the value of it, read it directly:
if (YourMod_Data[svName]["show"]) then

Anything in the table YourMod_Data will automatically save, because the TOC file specifies that table as something TO save.

Also of note, you can now use the line ## SavedVariablesPerCharacter in the TOC file, to save stuff for ONLY that character -- BUT you cannot ever access the settings for any other character if you do so (such as for 'copying' one char's settings to another, like Titan Panel 2 does).

Hope this helps.
__________________
Dsanai - nElf Hunter
Glacialfox - nElf Death Knight
Evilianti - Gnome Warlock
DSanai is offline   Reply With Quote
Unread 11-22-05, 12:39 AM   #3
shouryuu
A Chromatic Dragonspawn
 
shouryuu's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2005
Posts: 150
Thanks a lot man! My problem was solved when Iriel told my variables shouldn't be local :P Stupid 'lil 'ol me But thanks though, I did learn a few things with your post, keeping it for future reference.
shouryuu is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » SavedVariables

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