View Single Post
11-05-22, 09:40 AM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Like I said, saved variables aren't loaded until the ADDON_LOADED event fires. While you solved printing them to chat, the rest of your code is still trying to use them at file load.

https://wowpedia.fandom.com/wiki/AddOn_loading_process

The client reads your toc file, then it loads files you listed executing all lines of code as they load. Once all files in a toc are loaded, the client then loads the associated saved variables, then finally fires ADDON_LOADED. This means, for example, at line 37 in your second post here, "HMMVars.BagButtonVisable" will always be nil, not true or false.

You also still have that unused Frame object with PLAYER_LOGIN registered. Since you haven't shared your toc file, I'm also assuming your only saved variable is currently the table object HMMVars and not the individual booleans you spoke of originally.

I put everything in the PLAYER_LOGIN event:

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