Originally Posted by Vrul
No. The 'get' and 'set' fields are inherited so using a simple save structure allows you to use fewer generic get/set functions. If you insist on a needlessly complex save table then you will have to make more get/set functions for each unique case.
|
Really?!
I mean I had those inherited getter and setter for those child options, but it didn't really update the values...
Let me have a look first!
SO EXCITED
EDIT #1
Yeap, you are totally right, Vrul.
I was an idiot.
It was a logical error and here's what happened.
My actual code of getting those general options were like this.
Lua Code:
function CreateGeneralOption()
local _selectedUnit = string.lower(selectedUnit);
local setting = db.global.module.unitframe;
local option = {
order = GetOrder(),
type = "group",
name = "General",
get = function(info)
local value;
local opt = info[#info];
if opt == "p" or opt == "rT" or opt == "rP" or opt == "oX" or opt == "oY" then
value = tostring(setting[_selectedUnit].point[info[#info]]); -- Won't print 0 if not turned into string
else
value = setting[_selectedUnit][info[#info]];
end
return value;
end,
args = {
width = {
order = 1,
type = "range",
name = "Width",
min = 128,
max = 512,
step = 1,
set = function(info, ...)
setting[_selectedUnit].width = ...;
Module.frames[_selectedUnit]:SetWidth(setting[_selectedUnit].width);
end,
},
split1 = {
order = 2,
type = "header",
name = "",
},
p = {
order = 3,
type = "select",
name = "Point",
values = anchorList,
},
rT = {
order = 4,
type = "input",
name = "Relative To",
},
rP = {
order = 5,
type = "select",
name = "Relative Point",
values = anchorList,
},
oX = {
order = 6,
type = "input",
name = "X-Offset",
},
oY = {
order = 7,
type = "input",
name = "Y-Offset",
},
},
};
return option;
end
The
_selectedUnit was never getting updated to newly selected unit and so, the db was always referrring to player's one even if the selected unit changes.
Which should actually be something like
Lua Code:
function CreateGeneralOption()
local setting = db.global.module.unitframe;
local option = {
order = GetOrder(),
type = "group",
name = "General",
get = function(info)
local _selectedUnit = string.lower(selectedUnit);
local value;
local opt = info[#info];
if opt == "p" or opt == "rT" or opt == "rP" or opt == "oX" or opt == "oY" then
value = tostring(setting[_selectedUnit].point[info[#info]]); -- Won't print 0 if not turned into string
else
value = setting[_selectedUnit][info[#info]];
end
return value;
end,
args = {
width = {
order = 1,
type = "range",
name = "Width",
min = 128,
max = 512,
step = 1,
set = function(info, ...)
local _selectedUnit = string.lower(selectedUnit);
setting[_selectedUnit].width = ...;
Module.frames[_selectedUnit]:SetWidth(setting[_selectedUnit].width);
end,
},
split1 = {
order = 2,
type = "header",
name = "",
},
p = {
order = 3,
type = "select",
name = "Point",
values = anchorList,
},
rT = {
order = 4,
type = "input",
name = "Relative To",
},
rP = {
order = 5,
type = "select",
name = "Relative Point",
values = anchorList,
},
oX = {
order = 6,
type = "input",
name = "X-Offset",
},
oY = {
order = 7,
type = "input",
name = "Y-Offset",
},
},
};
return option;
end
Now it's working perfectly well!
Thank you so much for enlightening me