-
Posted by aeger on Thu, 05 Sep 2013 04:50:50
I've been spinning my wheels all day trying to get a frame to hide. The frame is from addon Bazooka and is called BazookaBar_1 when I use /framestack.
When I try to hide it I get an error attempt to index global BazookaBar1 a nil value. Below is my current code. I've tried Bazooka.BazookaBar1 as well. How do I make a frame from another addon local? Or is there a better way to do this? Thanks in advance.
local function topmenudisplay() if TopmenuShow == 1 then topmenu:Show() topmenuborder:Show() BazookaBar_1:Show() end if TopmenuShow == nil then topmenu:Hide() topmenuborder:Hide() BazookaBar_1:Hide() end end
-
Posted by jnwhiteh on Thu, 05 Sep 2013 17:38:46
You don't have to make it local, you can just refer to it using the global name, if it has one.
/dump GetMouseFocus():GetName()
Then to try and hide it:
/run _G[GetMouseFocus():GetName()]:Hide()
-
Posted by aeger on Thu, 05 Sep 2013 19:26:05
if I type the command in chat window it works fine. I get same error when I added it to the
function. function topmenudisplay() if TopmenuShow == 1 then topmenu:Show() topmenuborder:Show() _G["BazookaBar_1"]:Show() else if TopmenuShow == nil then topmenu:Hide() topmenuborder:Hide() _G["BazookaBar_1"]:Hide() end end end
-
Posted by jnwhiteh on Thu, 05 Sep 2013 19:53:00
The frame probably doesn't exist at that point. You have to wait until everything's been initialized and loaded.
-
Posted by aeger on Thu, 05 Sep 2013 19:55:23
I have Bazooka set as a dependency. Wouldn't everything be loaded before my addon?
-
Posted by jnwhiteh on Thu, 05 Sep 2013 20:01:23
No. Many addons don't do things until after one of the loading events.
-
Posted by aeger on Thu, 05 Sep 2013 21:14:40
Since the command works like I want it to. Should I suppress the error somehow or figure out a way to make sure the BazookBar_1 is initialized before running the function?
-
Posted by aeger on Thu, 05 Sep 2013 22:00:21
I got the error to stop by changing the function to this. Seems like this will be a lot of overhead. Is there a better way to to it?
topmenu:SetScript("OnEvent", function(self, event, ...) local timeleft = 1 --set the countdown to w/e you want local f = CreateFrame("Frame", nil, UIParent) f:SetScript("OnUpdate", function(_,arg) timeleft = timeleft - arg if timeleft >= 0 then timeleft = nil f:SetScript("OnUpdate", nil) topmenudisplay() end end) end)
-
Posted by jnwhiteh on Fri, 06 Sep 2013 04:37:17
Two things, you should register the appropriate event and make sure that your code runs after the other code. There's no overhead to this.
This just adds a static time. You would be better off waiting until one of the loading events and then checking and triggering a timer only if it still hasn't loaded.