Originally Posted by Dorwido
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.