Thread Tools Display Modes
09-05-13, 11:23 AM   #1
almty1
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 13
Issue hiding a BazookaBar

I having problems hiding BazookaBar_1 a bar from the addon Bazooka. I get the error below even though the frame actually hides and shows based off my saved variable.

topmenu.lua:21: attempt to index global "BazookaBar_1" (a nil value)

I've tried
Lua Code:
  1. local b1 = _G["Bazooka.BazookaBar_1"]
declared at top of page and within the function and get the same error. I think it was actually detecting it as a local variable at some point I don't remember how I had it but I was getting a different error about indexing a upvalue. I thought I was on the right track there so I added Bazooka as a dependency to make sure it was loaded first but that was no fix. What am I doing wrong in my topmenudisplay() function?

Lua Code:
  1. local aegerUI = ...
  2. local MEDIAPATH = "Interface\\AddOns\\aegerUI\\Media\\"
  3. local classcolor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]
  4.  
  5. local topmenu = CreateFrame("Frame", "topmenu", UIParent)
  6. topmenu:RegisterEvent("ADDON_LOADED")
  7. topmenu:RegisterEvent("ONUPDATE")
  8. topmenu:RegisterEvent("ONLOAD")
  9. topmenu:Hide()
  10.  
  11. local topmenuborder = CreateFrame("Frame", "topmenuborder", UIParent)
  12. topmenuborder:RegisterEvent("PLAYER_REGEN_ENABLED")
  13. topmenuborder:RegisterEvent("PLAYER_REGEN_DISABLED")
  14. topmenuborder:Hide()
  15.  
  16. function topmenudisplay()
  17.  
  18. if TopmenuShow == 1 then
  19. topmenu:Show()
  20. topmenuborder:Show()
  21. BazookaBar_1:Show()
  22. else
  23. if TopmenuShow == nil then
  24. topmenu:Hide()
  25. topmenuborder:Hide()
  26. BazookaBar_1:Hide()
  27. end
  28. end
  29. end
  30.  
  31. topmenu:SetScript("OnEvent", function(self, event, ...)
  32. topmenudisplay()
  33. end)
  34.  
  35. local function flip(texture,horizontal)
  36.     local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = texture:GetTexCoord()
  37.     if horizontal then
  38.         texture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
  39.     else
  40.         texture:SetTexCoord(LLx, LLy,ULx, ULy, LRx, LRy, URx, URy)
  41.     end
  42. end
  43.  
  44. topmenu:SetScript("OnShow", function(self)
  45.   self:SetScript("OnShow", nil)
  46.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  47.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  48.  
  49.   local tmdisplay = self:CreateTexture(nil, "BACKGROUND")
  50.     tmdisplay:SetSize(500, 36)
  51.     tmdisplay:SetPoint("TOP", UIParent, "TOP",0 ,3)
  52.     tmdisplay:SetPoint("CENTER", UIParent, "CENTER")
  53.     tmdisplay:SetTexture(MEDIAPATH .. "topmenu")
  54.     tmdisplay:SetVertexColor(0, 0, 0, .5)
  55.     flip(tmdisplay,false)
  56.    
  57. end)
  58.  
  59. topmenuborder:SetScript("OnShow", function(self)
  60.  
  61.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  62.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  63.  
  64.   local tmborderdisplay = self:CreateTexture(nil, "BORDER")
  65.     tmborderdisplay:SetSize(502, 46)
  66.     tmborderdisplay:SetPoint("TOP", UIParent, "TOP", 0, 10)
  67.     tmborderdisplay:SetPoint("CENTER", UIParent, "CENTER")
  68.     tmborderdisplay:SetTexture(MEDIAPATH .. "topmenuborder")
  69.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  70.     flip(tmborderdisplay,false)
  71.     topmenuborder:HookScript("OnEvent", function(self, event)
  72.     if event == "PLAYER_REGEN_DISABLED" then
  73.     tmborderdisplay:SetVertexColor(1, 0, 0)
  74.     elseif event == "PLAYER_REGEN_ENABLED" then
  75.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  76. end
  77. end)
  78. end)
  79.  
  80. SlashCmdList.TOPMENUSHOW = function()
  81.     TopmenuShow = 1
  82.     ReloadUI()
  83. end
  84. SLASH_TOPMENUSHOW1 = "/tmshow"
  85.  
  86. SlashCmdList.TOPMENUHIDE = function()
  87.     TopmenuShow = nil
  88.     ReloadUI()
  89. end
  90. SLASH_TOPMENUHIDE1 = "/tmhide"

Last edited by almty1 : 09-05-13 at 11:27 AM. Reason: typo
  Reply With Quote
09-05-13, 12:19 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
The "Bazooka" variable is actually a local.

Lua Code:
  1. local AppName, Bazooka = ...

So when you create a variable with this "Bazooka" local table: Bazooka.BazookaBar_1, that also gonna be local.

This means you cant reach any variable which got that "Bazooka" table in it, unless you edit into the Bazooka addon itself, or it's .toc file.

Last edited by Resike : 09-05-13 at 12:22 PM.
  Reply With Quote
09-05-13, 01:40 PM   #3
almty1
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 13
any idea how KGPanels does it without modifying Bazooka?
  Reply With Quote
09-05-13, 03:36 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
What does kgPanels have to do with Bazooka?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-05-13, 04:07 PM   #5
almty1
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 13
Originally Posted by Seerah View Post
What does kgPanels have to do with Bazooka?
Hey, thanks for looking at this. I started this addon so I could display my bottom bars without using KGPanels. I was simply able to hide this bazookaBar in a script in KGPanels is why I mentioned that. I think I figured out the issue though it seems kind of hacky. I'm trying to hide the panel before its initialized. The code below stopped the error from popping up. I made a delay in the topmenu on event script. Bazooka must be creating the frame after a event that hasn't happened yet when I try to run my function.

Lua Code:
  1. local aegerUI = ...
  2.  
  3. local MEDIAPATH = "Interface\\AddOns\\aegerUI\\Media\\"
  4. local classcolor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]
  5.  
  6.  
  7. local topmenu = CreateFrame("Frame", "topmenu", UIParent)
  8. topmenu:RegisterEvent("ADDON_LOADED")
  9. topmenu:RegisterEvent("ONUPDATE")
  10. topmenu:RegisterEvent("ONLOAD")
  11. topmenu:Hide()
  12.  
  13. local topmenuborder = CreateFrame("Frame", "topmenuborder", UIParent)
  14. topmenuborder:RegisterEvent("PLAYER_REGEN_ENABLED")
  15. topmenuborder:RegisterEvent("PLAYER_REGEN_DISABLED")
  16. topmenuborder:Hide()
  17.  
  18. function topmenudisplay()
  19.  
  20. if TopmenuShow == 1 then
  21. topmenu:Show()
  22. topmenuborder:Show()
  23. _G["BazookaBar_1"]:Show()
  24. else
  25. if TopmenuShow == nil then
  26. topmenu:Hide()
  27. topmenuborder:Hide()
  28. _G["BazookaBar_1"]:Hide()
  29. end
  30. end
  31. end
  32.  
  33. topmenu:SetScript("OnEvent", function(self, event, ...)
  34. local timeleft = 1 --set the countdown to w/e you want
  35. local f = CreateFrame("Frame", nil, UIParent)
  36. f:SetScript("OnUpdate", function(_,arg)
  37.   timeleft = timeleft - arg
  38.   if timeleft >= 0 then
  39.     timeleft = nil
  40.     f:SetScript("OnUpdate", nil)
  41.     topmenudisplay()
  42.   end
  43. end)
  44. end)
  45.  
  46. local function flip(texture,horizontal)
  47.     local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = texture:GetTexCoord()
  48.     if horizontal then
  49.         texture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
  50.     else
  51.         texture:SetTexCoord(LLx, LLy,ULx, ULy, LRx, LRy, URx, URy)
  52.     end
  53. end
  54.  
  55. topmenu:SetScript("OnShow", function(self)
  56.   self:SetScript("OnShow", nil)
  57.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  58.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  59.  
  60.   local tmdisplay = self:CreateTexture(nil, "BACKGROUND")
  61.     tmdisplay:SetSize(500, 36)
  62.     tmdisplay:SetPoint("TOP", UIParent, "TOP",0 ,3)
  63.     tmdisplay:SetPoint("CENTER", UIParent, "CENTER")
  64.     tmdisplay:SetTexture(MEDIAPATH .. "topmenu")
  65.     tmdisplay:SetVertexColor(0, 0, 0, .5)
  66.     flip(tmdisplay,false)
  67.    
  68. end)
  69.  
  70. topmenuborder:SetScript("OnShow", function(self)
  71.  
  72.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  73.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  74.  
  75.   local tmborderdisplay = self:CreateTexture(nil, "BORDER")
  76.     tmborderdisplay:SetSize(502, 46)
  77.     tmborderdisplay:SetPoint("TOP", UIParent, "TOP", 0, 10)
  78.     tmborderdisplay:SetPoint("CENTER", UIParent, "CENTER")
  79.     tmborderdisplay:SetTexture(MEDIAPATH .. "topmenuborder")
  80.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  81.     flip(tmborderdisplay,false)
  82.     topmenuborder:HookScript("OnEvent", function(self, event)
  83.     if event == "PLAYER_REGEN_DISABLED" then
  84.     tmborderdisplay:SetVertexColor(1, 0, 0)
  85.     elseif event == "PLAYER_REGEN_ENABLED" then
  86.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  87. end
  88. end)
  89. end)
  90.  
  91. SlashCmdList.TOPMENUSHOW = function()
  92.     TopmenuShow = 1
  93.     ReloadUI()
  94. end
  95. SLASH_TOPMENUSHOW1 = "/tmshow"
  96.  
  97. SlashCmdList.TOPMENUHIDE = function()
  98.     TopmenuShow = nil
  99.     ReloadUI()
  100. end
  101. SLASH_TOPMENUHIDE1 = "/tmhide"
  Reply With Quote
09-05-13, 08:18 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Ah, I must have misunderstood you then.

That's what I figured may have been your issue. Glad you got it sorted out.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-06-13, 01:58 AM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by almty1 View Post
Hey, thanks for looking at this. I started this addon so I could display my bottom bars without using KGPanels. I was simply able to hide this bazookaBar in a script in KGPanels is why I mentioned that. I think I figured out the issue though it seems kind of hacky. I'm trying to hide the panel before its initialized. The code below stopped the error from popping up. I made a delay in the topmenu on event script. Bazooka must be creating the frame after a event that hasn't happened yet when I try to run my function.

Lua Code:
  1. local aegerUI = ...
  2.  
  3. local MEDIAPATH = "Interface\\AddOns\\aegerUI\\Media\\"
  4. local classcolor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]
  5.  
  6.  
  7. local topmenu = CreateFrame("Frame", "topmenu", UIParent)
  8. topmenu:RegisterEvent("ADDON_LOADED")
  9. topmenu:RegisterEvent("ONUPDATE")
  10. topmenu:RegisterEvent("ONLOAD")
  11. topmenu:Hide()
  12.  
  13. local topmenuborder = CreateFrame("Frame", "topmenuborder", UIParent)
  14. topmenuborder:RegisterEvent("PLAYER_REGEN_ENABLED")
  15. topmenuborder:RegisterEvent("PLAYER_REGEN_DISABLED")
  16. topmenuborder:Hide()
  17.  
  18. function topmenudisplay()
  19.  
  20. if TopmenuShow == 1 then
  21. topmenu:Show()
  22. topmenuborder:Show()
  23. _G["BazookaBar_1"]:Show()
  24. else
  25. if TopmenuShow == nil then
  26. topmenu:Hide()
  27. topmenuborder:Hide()
  28. _G["BazookaBar_1"]:Hide()
  29. end
  30. end
  31. end
  32.  
  33. topmenu:SetScript("OnEvent", function(self, event, ...)
  34. local timeleft = 1 --set the countdown to w/e you want
  35. local f = CreateFrame("Frame", nil, UIParent)
  36. f:SetScript("OnUpdate", function(_,arg)
  37.   timeleft = timeleft - arg
  38.   if timeleft >= 0 then
  39.     timeleft = nil
  40.     f:SetScript("OnUpdate", nil)
  41.     topmenudisplay()
  42.   end
  43. end)
  44. end)
  45.  
  46. local function flip(texture,horizontal)
  47.     local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = texture:GetTexCoord()
  48.     if horizontal then
  49.         texture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
  50.     else
  51.         texture:SetTexCoord(LLx, LLy,ULx, ULy, LRx, LRy, URx, URy)
  52.     end
  53. end
  54.  
  55. topmenu:SetScript("OnShow", function(self)
  56.   self:SetScript("OnShow", nil)
  57.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  58.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  59.  
  60.   local tmdisplay = self:CreateTexture(nil, "BACKGROUND")
  61.     tmdisplay:SetSize(500, 36)
  62.     tmdisplay:SetPoint("TOP", UIParent, "TOP",0 ,3)
  63.     tmdisplay:SetPoint("CENTER", UIParent, "CENTER")
  64.     tmdisplay:SetTexture(MEDIAPATH .. "topmenu")
  65.     tmdisplay:SetVertexColor(0, 0, 0, .5)
  66.     flip(tmdisplay,false)
  67.    
  68. end)
  69.  
  70. topmenuborder:SetScript("OnShow", function(self)
  71.  
  72.   PetBattleFrame:HookScript("OnShow",function() self:Hide() end)
  73.   PetBattleFrame:HookScript("OnHide",function() self:Show() end)
  74.  
  75.   local tmborderdisplay = self:CreateTexture(nil, "BORDER")
  76.     tmborderdisplay:SetSize(502, 46)
  77.     tmborderdisplay:SetPoint("TOP", UIParent, "TOP", 0, 10)
  78.     tmborderdisplay:SetPoint("CENTER", UIParent, "CENTER")
  79.     tmborderdisplay:SetTexture(MEDIAPATH .. "topmenuborder")
  80.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  81.     flip(tmborderdisplay,false)
  82.     topmenuborder:HookScript("OnEvent", function(self, event)
  83.     if event == "PLAYER_REGEN_DISABLED" then
  84.     tmborderdisplay:SetVertexColor(1, 0, 0)
  85.     elseif event == "PLAYER_REGEN_ENABLED" then
  86.     tmborderdisplay:SetVertexColor(classcolor.r, classcolor.g, classcolor.b, 1.0)
  87. end
  88. end)
  89. end)
  90.  
  91. SlashCmdList.TOPMENUSHOW = function()
  92.     TopmenuShow = 1
  93.     ReloadUI()
  94. end
  95. SLASH_TOPMENUSHOW1 = "/tmshow"
  96.  
  97. SlashCmdList.TOPMENUHIDE = function()
  98.     TopmenuShow = nil
  99.     ReloadUI()
  100. end
  101. SLASH_TOPMENUHIDE1 = "/tmhide"
The frame names in your code should be nils:

Lua Code:
  1. local topmenu = CreateFrame("Frame", nil, UIParent)
  2. local topmenuborder = CreateFrame("Frame",nil, UIParent)

Else your frames gonna be globals.
  Reply With Quote
09-06-13, 09:59 AM   #8
almty1
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 13
Originally Posted by Resike View Post
The frame names in your code should be nils:

Lua Code:
  1. local topmenu = CreateFrame("Frame", nil, UIParent)
  2. local topmenuborder = CreateFrame("Frame",nil, UIParent)

Else your frames gonna be globals.
I need the frames to be global because I have a DataBroker plugin that shows/hides the frames with mouse clicks. I tested it just now with your suggestions and I get an error with the name being nil. So I changed it back. Thank you for taking the time to look and my code. I appreciate any help or advice.
  Reply With Quote
09-06-13, 05:40 PM   #9
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Is there a particular reason for the DataBroker plugin to be a separate AddOn from the one it manipulates? If so, I suggest better naming conventions - having generic names such as "TopmenuShow", "topmenu", "topmenuborder", and "topmenudisplay" is a good way to have a collision with someone else who uses such names, and you'd be better served by prefixing them with the name of your AddOn.

Another thing you're doing is creating frames, functions, and textures, and hooking scripts, every time something occurs - functions are garbage-collected, but creating them willy-nilly is almost never a good idea. Frames and textures are never garbage-collected, so you are needlessly and continually growing your memory usage.

I was going to rework some of your code to fix the issues, but without knowing about the DataBroker plugin, I thought it should wait.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
09-06-13, 07:16 PM   #10
almty1
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 13
I have my setup on git at https://github.com/aeger/AegerUI and I recently uploaded my whole setup here at http://www.wowinterface.com/download...3-aegerUI.html

the databroker plugin I made is in the modules folder I was trying to keep everything organized from the start. If you can show me a better way to do this I would appreciate it. I'm really new to LUA or programming anything really. I've been working as I go reading World of Warcraft programming 2nd edition by James Whitehead.
  Reply With Quote
09-06-13, 07:40 PM   #11
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
I'll take a look at it sometime over the weekend and see what I can see.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue hiding a BazookaBar


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