View Single Post
03-05-15, 08:22 AM   #37
flow0284
A Cyclonian
Join Date: Jan 2015
Posts: 40
Originally Posted by Dorwido View Post
Bei sowas wie Standardeinstellung finde ich übrigens Metatabellen recht handlich:

Code:
local defaultconf = {["GlobalConf"]=true,["TimeOnMission"]=true,["CounterTraits"]=true,["AutoPlace"]=true,["ShowTimeLeft"]=true,["FollowerRequired"]=true,["QuickAssign"]=true,["GoldExpShow"]=true,
					["HideAlert"]=false,["ShowCounterFollower"]=true,["ShowItemlevelFollower"]=true};

local metatable = {};

metatable.__index = function( inTable, inKey )
  value = defaultconf[inKey];
  inTable[ inKey ] = value;
  return value;
end

setmetatable(GarrisonMissonEnhancedGlobalConfig,metatable);
Das ist ne auszug aus eines meiner addons, GarrisonMissonEnhancedGlobalConfig ist dabei die savedvariable, wenn ich nun aufrufe GarrisonMissonEnhancedGlobalConfig["TimeOnMission"] und das existiert nicht in der saved variable dann wird die standardeinstellung übernommen, so kann man problemlos die standard config erweitern ohne das man in der savedvariable checken muss ob die neue option existiert oder nicht und wenn nicht hinzufügen.
Metatabellen hab ich irgendwo schon mal gelesen aber noch nie mit befasst.
Werden mal demnächst schauen wie Metatabellen funktionieren.
  Reply With Quote