I’ll take a closer look at that in a couple days. Unfortunately I’m away from home for a bit so will be stuck looking at the forum on phone until then. At a glance though I noticed “CopyTable” and I didn’t think lua had that function, am I right to assume it’s a custom function something along the lines here: http://lua-users.org/wiki/CopyTable?
And finally, just a more general “practise” type question regarding Saved Variables. Is it better (maybe easier is a better word) to split them so you don’t have nested tables in them?
So instead of;
Settings = {
Anchor = "BOTTOMLEFT",
StartMinimized = true,
Results = {
{1, "27/2/22", "Win"},
{2, "03/03/22", "Loss"}
}
}
You’d have:
Settings = {
Anchor = "BOTTOMLEFT",
StartMinimized = true,
}
Results = {
{1, "27/2/22", "Win"},
{2, "03/03/22", "Loss"}
}
I mean ultimately, even with the latter approach there are still tables in the Results variable but I’m thinking it’s cleaner when working on them to use Results[1] than it is to use Settings.Results[1].
Yeah CopyTable is created by Blizzard. I forget which file it’s in, but if you search for ‘function CopyTable’ in the ui’s default code you’ll find it.
Nested tables are totally fine for settings and extremely common for addons of moderate or more complexity. You will find nested tables used a lot in Lua. I don’t think it’s something to avoid.
I won’t go far as to say it’s best practice to use them, because it all depends on what you need and what’s easier for you to maintain.
If you wanted to make things simpler (which is fine too), then you can have multiple savedvariables:
## SavedVariables: CarnSettings, CarnResults, CarnSomethingElse
## SavedVariabelsPerCharacter: CarnPerCharacter
And use them separately. This is kinda necessary if your addon has global and per-character settings at the same time.
1 Like
CopyTable is in TableUtil.lua in FrameXML.
function CopyTable(settings, shallow)
local copy = {};
for k, v in pairs(settings) do
if type(v) == "table" and not shallow then
copy[k] = CopyTable(v);
else
copy[k] = v;
end
end
return copy;
end
There are quite a few other useful table utilities in there as well.
1 Like
Cool. Thanks to all who replied. That clears some things up.