View Single Post
09-29-18, 05:46 PM   #5
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
Originally Posted by Vrul View Post
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:
  1. function CreateGeneralOption()
  2.     local _selectedUnit = string.lower(selectedUnit);
  3.    
  4.     local setting = db.global.module.unitframe;
  5.  
  6.     local option = {
  7.         order = GetOrder(),
  8.         type = "group",
  9.         name = "General",
  10.         get = function(info)
  11.             local value;
  12.             local opt = info[#info];
  13.             if opt == "p" or opt == "rT" or opt == "rP" or opt == "oX" or opt == "oY" then
  14.                 value = tostring(setting[_selectedUnit].point[info[#info]]); -- Won't print 0 if not turned into string
  15.             else
  16.                 value = setting[_selectedUnit][info[#info]];
  17.             end
  18.  
  19.             return value;
  20.         end,
  21.         args = {
  22.             width = {
  23.                 order = 1,
  24.                 type = "range",
  25.                 name = "Width",
  26.                 min = 128,
  27.                 max = 512,
  28.                 step = 1,
  29.                 set = function(info, ...)
  30.                     setting[_selectedUnit].width = ...;
  31.  
  32.                     Module.frames[_selectedUnit]:SetWidth(setting[_selectedUnit].width);
  33.                 end,
  34.             },
  35.             split1 = {
  36.                 order = 2,
  37.                 type = "header",
  38.                 name = "",
  39.             },
  40.             p = {
  41.                 order = 3,
  42.                 type = "select",
  43.                 name = "Point",
  44.                 values = anchorList,
  45.             },
  46.             rT = {
  47.                 order = 4,
  48.                 type = "input",
  49.                 name = "Relative To",
  50.             },
  51.             rP = {
  52.                 order = 5,
  53.                 type = "select",
  54.                 name = "Relative Point",
  55.                 values = anchorList,
  56.             },
  57.             oX = {
  58.                 order = 6,
  59.                 type = "input",
  60.                 name = "X-Offset",
  61.             },
  62.             oY = {
  63.                 order = 7,
  64.                 type = "input",
  65.                 name = "Y-Offset",
  66.             },
  67.         },
  68.     };
  69.  
  70.     return option;
  71. 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:
  1. function CreateGeneralOption()
  2.     local setting = db.global.module.unitframe;
  3.  
  4.     local option = {
  5.         order = GetOrder(),
  6.         type = "group",
  7.         name = "General",
  8.         get = function(info)
  9.             local _selectedUnit = string.lower(selectedUnit);
  10.  
  11.             local value;
  12.             local opt = info[#info];
  13.             if opt == "p" or opt == "rT" or opt == "rP" or opt == "oX" or opt == "oY" then
  14.                 value = tostring(setting[_selectedUnit].point[info[#info]]); -- Won't print 0 if not turned into string
  15.             else
  16.                 value = setting[_selectedUnit][info[#info]];
  17.             end
  18.  
  19.             return value;
  20.         end,
  21.         args = {
  22.             width = {
  23.                 order = 1,
  24.                 type = "range",
  25.                 name = "Width",
  26.                 min = 128,
  27.                 max = 512,
  28.                 step = 1,
  29.                 set = function(info, ...)
  30.                     local _selectedUnit = string.lower(selectedUnit);
  31.  
  32.                     setting[_selectedUnit].width = ...;
  33.  
  34.                     Module.frames[_selectedUnit]:SetWidth(setting[_selectedUnit].width);
  35.                 end,
  36.             },
  37.             split1 = {
  38.                 order = 2,
  39.                 type = "header",
  40.                 name = "",
  41.             },
  42.             p = {
  43.                 order = 3,
  44.                 type = "select",
  45.                 name = "Point",
  46.                 values = anchorList,
  47.             },
  48.             rT = {
  49.                 order = 4,
  50.                 type = "input",
  51.                 name = "Relative To",
  52.             },
  53.             rP = {
  54.                 order = 5,
  55.                 type = "select",
  56.                 name = "Relative Point",
  57.                 values = anchorList,
  58.             },
  59.             oX = {
  60.                 order = 6,
  61.                 type = "input",
  62.                 name = "X-Offset",
  63.             },
  64.             oY = {
  65.                 order = 7,
  66.                 type = "input",
  67.                 name = "Y-Offset",
  68.             },
  69.         },
  70.     };
  71.  
  72.     return option;
  73. end

Now it's working perfectly well!

Thank you so much for enlightening me

Last edited by Lyak : 09-29-18 at 06:04 PM.
  Reply With Quote