Thread Tools Display Modes
09-16-09, 12:15 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
if frame exsists.

is their any way to check to see if a frame exists? rather then is visible?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-16-09, 12:23 AM   #2
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
local frame = FrameName
local exists = frame and frame.GetFrameType and true or false
print(exists)

edit - WoWWiki docs say GetFrameType may not exist for all frames, I'm not sure when that's true. You could also use `SetScript` or another method that every frame should have.

Last edited by Katae : 09-16-09 at 12:38 AM.
  Reply With Quote
09-16-09, 12:33 AM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
print("exists")

fixed
__________________
"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-16-09, 12:44 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
well in the end i wouldnt want it to print. what it would need to do in the end is execute a handful of functions based on weather the frame existed or not.

I may have come up with another answer... i think going that rote was going to prove more difficult then necessary.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-16-09, 12:53 AM   #5
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
The code I posted will set the variable exists to true or false so you can use it as a condition, you don't need to print it.
  Reply With Quote
09-16-09, 01:33 AM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
and the idea i had did not work. so hmm im not sure i know how to use your code for what im doing here is a chunk its got a lot of repeat code which im leaving out just for showing whats going on....

somewhere in here it needs to somehow check to see if the frame even exists so if the person checks the minimap icon off this piece of code does not error on load because it does not find that frame at all.

Code:
local takeover = CreateFrame"Frame"
takeover:RegisterEvent("PLAYER_ENTERING_WORLD")
takeover:SetScript("OnEvent", function(self, event)
        LibDBIcon10_EasyDND:ClearAllPoints()
	LibDBIcon10_EasyDND:Hide();
	LibDBIcon10_EasyDND.ClearAllPoints = dummy
        LibDBIcon10_EasyDND.SetPoint = dummy
	LibDBIcon10_EasyDND.Show = dummy
	LibDBIcon10_EasyDND.Hide = dummy
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-16-09, 01:47 AM   #7
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Code:
local takeover = CreateFrame("Frame")
takeover:RegisterEvent("PLAYER_ENTERING_WORLD")
takeover:SetScript("OnEvent", function(self, event)
   if LibDBIcon10_EasyDND then
        LibDBIcon10_EasyDND:ClearAllPoints()
	LibDBIcon10_EasyDND:Hide();
	LibDBIcon10_EasyDND.ClearAllPoints = dummy
        LibDBIcon10_EasyDND.SetPoint = dummy
	LibDBIcon10_EasyDND.Show = dummy
	LibDBIcon10_EasyDND.Hide = dummy
   end
end)
Since the name of the frame seems to be static and you already know what it is, I don't really see the problem.
__________________
  Reply With Quote
09-16-09, 11:12 AM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Its not static....

i thought that to but it turns out none of the LDB icons, except for EasyDND which has an error in it that causes the button to appear no mater what which is why my code does not error on it ever, are not actually static.

Also a few non-LDB icons as well like WIM3's icon.

As it turns out or at lest this appears to be the case at any rate, that some of those icons frames are only created if the show minimap button option is checked within the addons options. Soooo what this means is that my chunk of code errors out if the option is set to hide the button. It seems to think the frame does not exist.

Ultimately its purpose is so that i no longer have to transfer WTF's with my UI for everything to set up properly. Minimap Icons on first install were just out of control IMO. Going threw and hiding them is a pain for me let alone the end user. Now i have made it so in its raw forum with no WTF's it does work properly, i just made sure that my code works on the principal that all addons load in default state, but the problem is if the end user clicks that hide minimap button option the next time they load the game it will error out.

Same issue occurs with the FubarFrame2 if you change fubar options so that their is only one bar the fubarframe2:hide tag errors.... also an issue i foresee is how to make it only do all of this on the first load up. it in reality should be able to allow for end user to adjust and it not reset but the way i have done this so far it will reset every time someone logs in or out or for that mater zones.... or /reloads

the whole code looks like this.....

Code:
local dummy = function() end
local takeover = CreateFrame"Frame"
takeover:RegisterEvent("PLAYER_LOGIN")
takeover:SetScript("OnEvent", function(self, event)
    
	ChatFrame1:ClearAllPoints()
    ChatFrame1:SetPoint("BOTTOMLEFT", GrimUIcoreArtB1, "BOTTOMLEFT", 14, 25)
    ChatFrame1:SetWidth(350)
	ChatFrame1:SetHeight(190)
	ChatFrame1:SetFrameLevel(10)
	ChatFrame1UpButton:Hide();
	ChatFrame1DownButton:Hide();
	ChatFrame1.ClearAllPoints = dummy
    ChatFrame1.SetPoint = dummy
	ChatFrame1UpButton.Show = dummy
	ChatFrame1DownButton.Show = dummy
	
    ChatFrame5:ClearAllPoints()
    ChatFrame5:SetPoint("BOTTOMRIGHT", GrimUIcoreArtB4, "BOTTOMRIGHT", -13, 17)
    ChatFrame5:SetWidth(235)
	ChatFrame5:SetHeight(110)
	ChatFrame5UpButton:Hide();
	ChatFrame5DownButton:Hide();
	ChatFrame5.ClearAllPoints = dummy
    ChatFrame5.SetPoint = dummy
	
	ChatFrame2:ClearAllPoints()
    ChatFrame2:SetPoint("BOTTOMRIGHT", ChatFrame5, "BOTTOMLEFT", -7, 0)
    ChatFrame2:SetWidth(118)
	ChatFrame2:SetHeight(110)
	ChatFrame2UpButton:Hide();
	ChatFrame2DownButton:Hide();
	ChatFrame2.ClearAllPoints = dummy
    ChatFrame2.SetPoint = dummy

	MainMenuBar:Hide();	
	FuBarFrame1:Hide();
	FuBarFrame2:Hide();	
	
	MiniMapWorldMapButton:ClearAllPoints()
	MiniMapWorldMapButton:Hide();
	MiniMapWorldMapButton.ClearAllPoints = dummy
    MiniMapWorldMapButton.SetPoint = dummy
	MiniMapWorldMapButton.Show = dummy 
	
	SmartBuff_MiniMapButton:ClearAllPoints()
	SmartBuff_MiniMapButton:Hide();
	SmartBuff_MiniMapButton.ClearAllPoints = dummy
    SmartBuff_MiniMapButton.SetPoint = dummy
	SmartBuff_MiniMapButton.Show = dummy 
	
	CritlineMinimapFrame:ClearAllPoints()
	CritlineMinimapFrame:Hide();
	CritlineMinimapFrame.ClearAllPoints = dummy
    CritlineMinimapFrame.SetPoint = dummy
	CritlineMinimapFrame.Show = dummy

	TrinketMenu_IconFrame:ClearAllPoints()
	TrinketMenu_IconFrame:Hide();
	TrinketMenu_IconFrame.ClearAllPoints = dummy
    TrinketMenu_IconFrame.SetPoint = dummy
	TrinketMenu_IconFrame.Show = dummy 

	ItemRackMinimapFrame:ClearAllPoints()
	ItemRackMinimapFrame:Hide();
	ItemRackMinimapFrame.ClearAllPoints = dummy
    ItemRackMinimapFrame.SetPoint = dummy
	ItemRackMinimapFrame.Show = dummy 

	MI3_MinimapButton:ClearAllPoints()
	MI3_MinimapButton:Hide();
	MI3_MinimapButton.ClearAllPoints = dummy
    MI3_MinimapButton.SetPoint = dummy
	MI3_MinimapButton.Show = dummy

	FishingBuddyMinimapFrame:ClearAllPoints()
	FishingBuddyMinimapFrame:Hide();
	FishingBuddyMinimapFrame.ClearAllPoints = dummy
    FishingBuddyMinimapFrame.SetPoint = dummy
	FishingBuddyMinimapFrame.Show = dummy

	AltoholicMinimapButton:ClearAllPoints()
	AltoholicMinimapButton:Hide();
	AltoholicMinimapButton.ClearAllPoints = dummy
    AltoholicMinimapButton.SetPoint = dummy
	AltoholicMinimapButton.Show = dummy

	MacaroonMinimapButton:ClearAllPoints()
	MacaroonMinimapButton:Hide();
	MacaroonMinimapButton.ClearAllPoints = dummy
    MacaroonMinimapButton.SetPoint = dummy
	MacaroonMinimapButton.Show = dummy

	Gatherer_MinimapOptionsButton:ClearAllPoints()
	Gatherer_MinimapOptionsButton:Hide();
	Gatherer_MinimapOptionsButton.ClearAllPoints = dummy
    Gatherer_MinimapOptionsButton.SetPoint = dummy
	Gatherer_MinimapOptionsButton.Show = dummy
	
	DBMMinimapButton:ClearAllPoints()
	DBMMinimapButton:Hide();
	DBMMinimapButton.ClearAllPoints = dummy
    DBMMinimapButton.SetPoint = dummy
	DBMMinimapButton.Show = dummy 
end)

local hostiletakeover = CreateFrame"Frame"
hostiletakeover:RegisterEvent("PLAYER_ENTERING_WORLD")
hostiletakeover:SetScript("OnEvent", function(self, event)
	
	Minimap:ClearAllPoints()
	Minimap:SetPoint("CENTER", UIParent)
	Minimap:SetPoint("BOTTOM", UIParent, 0, 10)
	Minimap:SetHeight(127)
		Minimap.SetHeight = dummy
	MinimapZoomIn:Hide();
	MinimapZoomOut:Hide();
	MinimapBackdrop:Hide();
		MinimapBackdrop.Show = dummy
	Minimap:SetBackdropBorderColor(nil, nil, nil, nil)
	Minimap.SetBackdropBorderColor = dummy
	Minimap:SetMaskTexture([[Interface\AddOns\GrimUIcore\Masks\Mask-SQUARE]])
	GameTimeFrame:Hide();
	Minimap.ClearAllPoints = dummy
	Minimap.SetPoint = dummy
	MinimapZoomIn.Show = dummy
	MinimapZoomOut.Show = dummy
	Minimap.SetWidth = dummy
	Minimap.SetMaskTexture = dummy
	
	LibDBIcon10_EasyDND:ClearAllPoints()
	LibDBIcon10_EasyDND:Hide();
	LibDBIcon10_EasyDND.ClearAllPoints = dummy
    LibDBIcon10_EasyDND.SetPoint = dummy
	LibDBIcon10_EasyDND.Show = dummy
	LibDBIcon10_EasyDND.Hide = dummy
	
	LibDBIcon10_sRaidFrames:ClearAllPoints()
	LibDBIcon10_sRaidFrames:Hide();
	LibDBIcon10_sRaidFrames.ClearAllPoints = dummy
	LibDBIcon10_sRaidFrames.SetPoint = dummy
	LibDBIcon10_sRaidFrames.Show = dummy
		
	WIM3MinimapButton:ClearAllPoints()
	WIM3MinimapButton:Hide();
	WIM3MinimapButton.ClearAllPoints = dummy
    WIM3MinimapButton.SetPoint = dummy
	WIM3MinimapButton.Show = dummy
	
	LibDBIcon10_oRA2:ClearAllPoints()
	LibDBIcon10_oRA2:Hide();
	LibDBIcon10_oRA2.ClearAllPoints = dummy
    LibDBIcon10_oRA2.SetPoint = dummy
	LibDBIcon10_oRA2.Show = dummy
	
	LibDBIcon10_AutoBar:ClearAllPoints()
	LibDBIcon10_AutoBar:Hide();
	LibDBIcon10_AutoBar.ClearAllPoints = dummy
    LibDBIcon10_AutoBar.SetPoint = dummy
	LibDBIcon10_AutoBar.Show = dummy
	
	LibDBIcon10_BugSack:ClearAllPoints()
	LibDBIcon10_BugSack:Hide();
	LibDBIcon10_BugSack.ClearAllPoints = dummy
    LibDBIcon10_BugSack.SetPoint = dummy
	LibDBIcon10_BugSack.Show = dummy
	
	LibDBIcon10_Broker_Auditor:ClearAllPoints()
	LibDBIcon10_Broker_Auditor:Hide();
	LibDBIcon10_Broker_Auditor.ClearAllPoints = dummy
    LibDBIcon10_Broker_Auditor.SetPoint = dummy
	LibDBIcon10_Broker_Auditor.Show = dummy
	
	DHUDMinimapButton:ClearAllPoints()
	DHUDMinimapButton:Hide();
	DHUDMinimapButton.ClearAllPoints = dummy
    DHUDMinimapButton.SetPoint = dummy
	DHUDMinimapButton.Show = dummy
	DHUDMinimapButton.Hide = dummy
	end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-16-09, 12:05 PM   #9
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
As Tristanian suggested, you need to check if the button/frame exists before actually doing something on it.
I've refactored your code a bit to keep it more readable: http://pastey.net/125272

All frames that need to be hidden are defined in the table at the top - after PLAYER_ENTERING_WORLD, the code will check if the frame exists and then hides it.

Regarding to doing this only on first loadup: Well, as far as I know this could become very complicated with your current code, because you would have to check for each button whether the user actually enables it or not ... which kinda defeats your complete "force this button to stay hidden"-approach. This also causes the button to be hidden while the addon's config screen still says that it's shown. I personally would go after SavedVariables if you want to have a "user-changeable default state".
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
09-16-09, 12:05 PM   #10
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
For the Fubar stuff just use a while loop.

Code:
local i = 1
while _G['FubarFrame'..i] do
     -- code will only execute if there's a global object called FubarFrameN
     -- this won't work if they're created non-sequentially, but that shouldn't be a problem.
     i = i + 1
end

For the data broker icons, I dunno. Seems sloppy but you could iterate through the global table.

Code:
for k, v in pairs(_G) do
     if strfind(k, 'LibDBIcon%d+_EasyDND') then
          -- frame exists
     end
end
There might be a better way to handle this through LDB itself, but I've never used it so I'm not familiar with the API.
  Reply With Quote
09-16-09, 12:15 PM   #11
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Actually Some things should be on a force always hide. some things should not lol. Hmm trying to think of a general structure for how to do the saved variables on this. I think the best way would be to make a saved variable and then have the addon check on load up if the saved variable exists do whats in that, if it does not then do this... have the if not do this force everything as seen in the current code. If it does exsist then it would load up what ever the end user has done. As you know though Carg, i dont know squat about variables yet

Originally Posted by Cargor View Post
As Tristanian suggested, you need to check if the button/frame exists before actually doing something on it.
I've refactored your code a bit to keep it more readable: http://pastey.net/125272

All frames that need to be hidden are defined in the table at the top - after PLAYER_ENTERING_WORLD, the code will check if the frame exists and then hides it.

Regarding to doing this only on first loadup: Well, as far as I know this could become very complicated with your current code, because you would have to check for each button whether the user actually enables it or not ... which kinda defeats your complete "force this button to stay hidden"-approach. This also causes the button to be hidden while the addon's config screen still says that it's shown. I personally would go after SavedVariables if you want to have a "user-changeable default state".
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
09-16-09, 12:17 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
It is possible correct, to make it so that it forces a default on load up but then saves any changes made to that setup on log out? i know this has to be somewhat possible because basic profiling does this. hmm alright well... going to finish with what should be the default setup then will work on the saved variables part and end user changes.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » if frame exsists.


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