Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-03-22, 08:52 PM   #1
Baz4k
A Deviate Faerie Dragon
 
Baz4k's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 12
I am getting my butt kicked by saved variables.

Bear with me, I am learning as I go. I am making an addon that can hide the new Dragonflight Micro Menu bar. I am learning by looking at other peoples online tutorials and it's slow, but I am making progress.

I've hit a wall when it comes to saving and loading variables. I have two variables that I am attempting to load. They are Booleans called BagButtonVisable and MicroMenuVisable.

I added them to the toc and successfully got them to save to the file, but they never loaded. I found some great tutorials from Phanx, I think they are a above my current level.

I will include what I have done so far. Any help would be greatly appreciated.

Lua Code:
  1. --Setup variables saving/loading
  2. ----------------------------------------------------------------------------------
  3.  
  4. HideMicroMenuDBPC = { }
  5.  
  6. function HideMicroMenuDBPC:PLAYER_LOGIN()
  7.     -- This table defines the addon's default settings:
  8.     local defaults = {
  9.         BagButtonVisable = true,
  10.         MicroMenuVisable = true,
  11.     }
  12.  
  13.     -- This function copies values from one table into another:
  14.     local function copyDefaults(src, dst)
  15.         -- If no source (defaults) is specified, return an empty table:
  16.         if type(src) ~= "table" then return {} end
  17.         -- If no target (saved variable) is specified, create a new table:
  18.         if not type(dst) then dst = {} end
  19.         -- Loop through the source (defaults):
  20.         for k, v in pairs(src) do
  21.             -- If the value is a sub-table:
  22.             if type(v) == "table" then
  23.                 -- Recursively call the function:
  24.                 dst[k] = copyDefaults(v, dst[k])
  25.             -- Or if the default value type doesn't match the existing value type:
  26.             elseif type(v) ~= type(dst[k]) then
  27.                 -- Overwrite the existing value with the default one:
  28.                 dst[k] = v
  29.             end
  30.         end
  31.         -- Return the destination table:
  32.         return dst
  33.     end
  34.  
  35.     -- Copy the values from the defaults table into the saved variables table
  36.     -- if it exists, and assign the result to the saved variable:
  37.     HideMicroMenuDBPC = copyDefaults(defaults, HideMicroMenuDBPC)
  38. end
  39.  
  40.  
  41.  
  42.  
  43. --Setup Options Panel
  44. ----------------------------------------------------------------------------------
  45. local Frame = CreateFrame("Frame")
  46. Frame:RegisterEvent("PLAYER_LOGIN")
  47.  
  48. HideMicroMenu = {};
  49. HideMicroMenu.panel = CreateFrame( "Frame", "HideMicroMenuPanel", UIParent );
  50. HideMicroMenu.panel.name = "Hide Micro Menu";
  51. InterfaceOptions_AddCategory(HideMicroMenu.panel);
  52.  
  53. -- Create BagButton Frame
  54. local BagButtonFrame = CreateFrame("Frame", nil, nil, "BackdropTemplate")
  55. BagButtonFrame:SetSize(50, 50)
  56. BagButtonFrame:SetBackdrop(BACKDROP_TUTORIAL_16_16)
  57. BagButtonFrame:ClearBackdrop()
  58. BagButtonFrame:SetPoint("CENTER", MainMenuBarBackpackButton, "CENTER", 0, -0)
  59.  
  60. --BagButton Button in Options
  61. BagButton = CreateFrame("Button", "BagButton", HideMicroMenuPanel, "UIPanelButtonTemplate");
  62. BagButton:SetSize(200 ,40)
  63. BagButton:SetText("Toggle Bag Button Visability")
  64. BagButton:SetPoint("TOPLEFT", 35, -65);
  65. BagButton:SetScript("OnClick",
  66.   function()
  67.     if BagButtonVisable == true then
  68.         BagButtonFrame:Hide()
  69.         BagButtonVisable = false
  70.         print ("BagButton ", BagButtonVisable)
  71.     else
  72.         BagButtonFrame:Show()
  73.         BagButtonVisable = true
  74.         print ("BagButton ", BagButtonVisable)
  75.     end
  76.   end
  77. );
  78.  
  79.  
  80. --MicroMenu Button in Options
  81. MicroMenu = CreateFrame("Button", "MicroMenu", HideMicroMenuPanel, "UIPanelButtonTemplate");
  82. MicroMenu:SetSize(200 ,40)
  83. MicroMenu:SetText("Toggle Micro Menu Visability")
  84. MicroMenu:SetPoint("TOPLEFT", 35, -165);
  85. MicroMenu:SetScript("OnClick",
  86.   function()
  87.     if MicroMenuVisable == true then
  88.         MicroButtonAndBagsBar:Hide()
  89.         MicroMenuVisable = false
  90.         print ("MicroMenu ", MicroMenuVisable)
  91.     else
  92.         MicroButtonAndBagsBar:Show()
  93.         MicroMenuVisable = true
  94.         print ("MicroMenu ", MicroMenuVisable)
  95.     end
  96.   end
  97. );
  98.  
  99.  
  100. --Setup Bag Button
  101. ----------------------------------------------------------------------------------
  102.  
  103.  
  104. MainMenuBarBackpackButton:SetParent(BagButtonFrame)
  105. MainMenuBarBackpackButton:SetScale (0.65)
  106. BagBarExpandToggle:ClearAllPoints()
  107. BagBarExpandToggle:SetParent(BagButtonFrame)
  108.  
  109.  
  110. if (BagButtonVisable == false) then
  111.     BagButtonFrame:Hide()
  112. else
  113.     BagButtonFrame:Show()
  114. end
  115.  
  116.  
  117. --Setup Micro Menu
  118. ----------------------------------------------------------------------------------
  119.  
  120. if (MicroMenuVisable == false) then
  121.     MicroButtonAndBagsBar:Hide()
  122. else
  123.     MicroButtonAndBagsBar:Show()
  124. end
  125.  
  126.  
  127. --Setup Queue Status
  128. ----------------------------------------------------------------------------------
  129.  
  130. local QueueButtonFrame = CreateFrame("Frame", nil, nil, "BackdropTemplate")
  131. QueueButtonFrame:SetPoint("CENTER", QueueStatusButton, "CENTER", 0, -0)
  132. QueueButtonFrame:SetSize(50, 50)
  133. QueueButtonFrame:SetBackdrop(BACKDROP_TUTORIAL_16_16)
  134. QueueButtonFrame:ClearBackdrop()
  135. QueueButtonFrameCenter = QueueButtonFrame:GetCenter()
  136. print (QueueButtonFrameCenter)
  137.  
  138. QueueStatusButton:SetParent(QueueButtonFrame)
  139. QueueStatusButton:SetScale (0.65)
  140.  
  141. --Make Queue Status Frame Draggable
  142. QueueStatusButton:SetMovable(true)
  143. QueueStatusButton:EnableMouse(true)
  144. QueueStatusButton:RegisterForDrag("LeftButton")
  145. QueueStatusButton:SetScript("OnDragStart", function(self, button)
  146.     self:StartMoving()
  147. end)
  148. QueueStatusButton:SetScript("OnDragStop", function(self)
  149.     self:StopMovingOrSizing()
  150. end)
  151. QueueStatusButton:SetUserPlaced(true)
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » I am getting my butt kicked by saved variables.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off