View Single Post
11-04-22, 11:21 AM   #3
Baz4k
A Deviate Faerie Dragon
 
Baz4k's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 12
Thanks for your help

Okay, I took some time to completely rewrite my code since I felt more confident that I understood what I was doing a little better. I now have the variables saving and loading properly, but I am not getting the desired result. I can tell that they are saving by looking at the lua file and I have a print command that fires when the game loads to tell that they are loading properly. I am trying to set the visibility of the Bag Button and the Micro Menu by using the saved variable. If the variable is FALSE then they should be hidden and visible when the variable is TRUE. But most of the time the Bag Button (for instance) will be visible even when the variable prints as FALSE.

What am I doing wrong?

Lua Code:
  1. ---------------------------------------
  2. --Setup variables saving/loading
  3. ---------------------------------------
  4.  
  5. HMMVars = {
  6.     BagButtonVisable = true,
  7.     MicroMenuVisable = true,
  8. }
  9.  
  10. local HMMFrame = CreateFrame("Frame")
  11. HMMFrame:RegisterEvent("ADDON_LOADED")
  12. HMMFrame:SetScript("OnEvent", function(self, event, addon)
  13.     if addon == "Hide Micro Menu" then
  14.         print("BagButton ", HMMVars.BagButtonVisable)
  15.         print("MicroMenu ", HMMVars.MicroMenuVisable)
  16.     end
  17. end)
  18.  
  19. ---------------------------------------
  20. --Create BagButton Frame
  21. ---------------------------------------
  22.  
  23. local BagButtonFrame = CreateFrame("Frame", nil, nil, "BackdropTemplate")
  24. BagButtonFrame:SetSize(50, 50)
  25. BagButtonFrame:SetBackdrop(BACKDROP_TUTORIAL_16_16)
  26. BagButtonFrame:ClearBackdrop()
  27. BagButtonFrame:SetPoint("CENTER", MainMenuBarBackpackButton, "CENTER", 0, -0)
  28. MainMenuBarBackpackButton:SetParent(BagButtonFrame)
  29. MainMenuBarBackpackButton:SetScale (0.65)
  30.  
  31. ---------------------------------------
  32. --Set BagButton Visability to variable
  33. ---------------------------------------
  34.  
  35. BagBarExpandToggle:SetParent(MainMenuBarBackpackButton) --Set the bag arrow as a child of the BagButton
  36.  
  37. if (HMMVars.BagButtonVisable == true) then
  38.     BagButtonFrame:Hide()
  39. else
  40.     BagButtonFrame:Show()
  41. end
  42.  
  43. ---------------------------------------
  44. --Set MicroMenu Visability to variable
  45. ---------------------------------------
  46.  
  47. if (HMMVars.MicroMenuVisable == false) then
  48.     MicroButtonAndBagsBar:Hide()
  49. else
  50.     MicroButtonAndBagsBar:Show()
  51. end
  52.  
  53. ---------------------------------------
  54. --Create Options Panel
  55. ---------------------------------------
  56.  
  57. local Frame = CreateFrame("Frame")
  58. Frame:RegisterEvent("PLAYER_LOGIN")
  59.  
  60. HideMicroMenu = {};
  61. HideMicroMenu.panel = CreateFrame( "Frame", "HideMicroMenuPanel", UIParent );
  62. HideMicroMenu.panel.name = "Hide Micro Menu";
  63. InterfaceOptions_AddCategory(HideMicroMenu.panel);
  64.  
  65. ---------------------------------------
  66. --Create BagButton Button in Options
  67. ---------------------------------------
  68.  
  69. BagButton = CreateFrame("Button", "BagButton", HideMicroMenuPanel, "UIPanelButtonTemplate");
  70. BagButton:SetSize(200 ,40)
  71. BagButton:SetText("Toggle Bag Button Visability")
  72. BagButton:SetPoint("TOPLEFT", 35, -65);
  73. BagButton:SetScript("OnClick",
  74.   function()
  75.     if HMMVars.BagButtonVisable == true then
  76.         BagButtonFrame:Hide()
  77.         HMMVars.BagButtonVisable = false
  78.         print ("BagButton ", HMMVars.BagButtonVisable)
  79.     else
  80.         BagButtonFrame:Show()
  81.         HMMVars.BagButtonVisable = true
  82.         print ("BagButton ", HMMVars.BagButtonVisable)
  83.     end
  84.   end
  85. );
  86.  
  87. ---------------------------------------
  88. --Create MicroMenu Button in Options
  89. ---------------------------------------
  90.  
  91. MicroMenu = CreateFrame("Button", "MicroMenu", HideMicroMenuPanel, "UIPanelButtonTemplate");
  92. MicroMenu:SetSize(200 ,40)
  93. MicroMenu:SetText("Toggle Micro Menu Visability")
  94. MicroMenu:SetPoint("TOPLEFT", 35, -165);
  95. MicroMenu:SetScript("OnClick",
  96.   function()
  97.     if HMMVars.MicroMenuVisable == true then
  98.         MicroButtonAndBagsBar:Hide()
  99.         HMMVars.MicroMenuVisable = false
  100.         print ("MicroMenu ", HMMVars.MicroMenuVisable)
  101.     else
  102.         MicroButtonAndBagsBar:Show()
  103.         HMMVars.MicroMenuVisable = true
  104.         print ("MicroMenu ", HMMVars.MicroMenuVisable)
  105.     end
  106.   end
  107. );
  108.  
  109. ---------------------------------------
  110. --Setup Queue Status Icon
  111. ---------------------------------------
  112.  
  113. local QueueButtonFrame = CreateFrame("Frame", nil, nil, "BackdropTemplate")
  114. QueueButtonFrame:SetPoint("CENTER", QueueStatusButton, "CENTER", 0, -0)
  115. QueueButtonFrame:SetSize(50, 50)
  116. --QueueButtonFrame:SetBackdrop(BACKDROP_TUTORIAL_16_16)
  117. --QueueButtonFrame:ClearBackdrop()
  118.  
  119. QueueStatusButton:SetParent(QueueButtonFrame)
  120. QueueStatusButton:SetScale (0.65)
  121. QueueStatusButton:SetMovable(true)
  122. QueueStatusButton:EnableMouse(true)
  123. QueueStatusButton:RegisterForDrag("LeftButton")
  124. QueueStatusButton:SetScript("OnDragStart", function(self, button)
  125.     self:StartMoving()
  126. end)
  127. QueueStatusButton:SetScript("OnDragStop", function(self)
  128.     self:StopMovingOrSizing()
  129. end)
  130. QueueStatusButton:SetUserPlaced(true)
  Reply With Quote