View Single Post
02-01-10, 06:15 PM   #30
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
Well, I found out an interesting thing while utilising this new feature in my latest addon.

Eg.

Code:
local MultipleAnchors = Variables["ScrollFrame"].MultipleAnchors;
print("Current Multiple Anchors in Use ? : ", MultipleAnchors);
Variables["ScrollFrame"].MultipleAnchors = true;
print("Old Multiple Anchors in Use ? : ", MultipleAnchors);
print("New Multiple Anchors in Use ? : ", Variables["ScrollFrame"].MultipleAnchors);
Initially it is defaulted to false and then set to true. I initially expected it to override the value in the stored table being that variables are pointers to another. Erm, I guess not in this instance. The first print shows false, the second shows false and the last print shows true. So to override a value in the table for use by other files, specify the table completely. To simply use a value locally without affecting the table you can use a local. Which I believe you all inferred but I didn't realise you meant it would work that way rofl.

Whats good about this is that I can now keep a set of default variables without fear of overwriting them if I then set them to a new variable table so in theory ( and I will be testing this shortly ) you could do this.

DefaultVars.lua
Code:
addonTable.Variables = {};
addonTable.Variables["Defaults"] = {};
addonTable.Variables["Defaults"].defaultVar1 = "blah"
addonTable.Variables["Defaults"].defaultTab1 = { item1 = "blah2", item2 = "blah3" }
etc
SpecialVars.lua
Code:
local DefaultVars = addonTable.Variables["Default"];
addonTable.Variables["Special"] = DefaultVars;
SavedVars.lua
Code:
local DefaultVars = addonTable.Variables["Default"];
SavedVars = DefaultVars;

function addonTable.Functions["SavedVars"].ResetDefaults()
  local DefaultVars = addonTable.Variables["Default"];
  SavedVars = DefaultVars;
end

etc
Main.lua
Code:
local DefaultVars = addonTable.Variables["Default"];
local SpecialVars = addonTable.Variables["Special"];

if slashCmdParam1 = "reset" then
  addonTable.Functions["SavedVars"].ResetDefaults()
  --UpdateAddonWithNewValues
end
Handy thing to know if you have a file holding generic data you always use such as background values, generic functions etc. Put them all in a file and use it in all your addons.

Edt: And this is probably what was breaking some parts of my addon as I was testing against values that had been overriden via a localised version of the variable expecting it to override the addonTable one.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 02-01-10 at 06:20 PM.
  Reply With Quote