Reply
Thread Tools Display Modes
Unread 06-30-12, 02:11 PM   #1
SRCarebear
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Mar 2009
Posts: 26
Making frame appear in combat. Hide out of combat.

I'm working on an edit of sFilter to track all general debuffs on the target. I renamed it to aFilter as I still use sFilter for personal buffs. I'm a little stuck though in trying to make the frame appear when I am only in combat.

Screenshots in combat:

http://i.imgur.com/LG565.jpg
http://i.imgur.com/Cljyl.jpg

Screenshot out of combat:

http://i.imgur.com/3UBP3.jpg

I have attempted to add some code to hide the frame out of combat and pop up for when I'm in combat but it only pops up for a second and then disappears again instantly.

I added
Code:
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
to the function, and also added

Code:
			
if event == "PLAYER_REGEN_DISABLED" then
self:Show()
else
self:Hide() 
end
end)
How do I make it appear for the whole duration of combat, and not just when I get into combat?
SRCarebear is offline   Reply With Quote
Unread 07-01-12, 01:52 AM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,376
Your code is currently saying "if this event is PLAYER_REGEN_DISABLED, show this frame, but if it's any other event, hide this frame". If you have any other events registered to the frame, the frame will be hidden whenever any event that is not PLAYER_REGEN_DISABLED occurs.

There are many ways to solve this problem. With no idea what the rest of your code looks like, I can't tell you which way is "best", though, so here are several:

(1) Unregister all other events on the same frame.

(2) Modify your event handler code to explicitly check whether the fired event is PLAYER_REGEN_ENABLED before hiding the frame:

Code:
if event == "PLAYER_REGEN_DISABLED" then
	self:Show()
elseif event == "PLAYER_REGEN_ENABLED" then
	self:Hide() 
end
(3) Modify your event handler code to show/hide the frame based on whether the player is currently engaged in combat, instead of based on which event fired:

Code:
if UnitAffectingCombat("player") then
	self:Show()
else
	self:Hide() 
end
Finally, when posting code and asking for help with it, please:

(1) Use indentation. It's not that bad when it's only 5 lines of code, but when you're posting 100+ lines of code with no indentation, it's basically unreadable, and nobody is going to bother trying to read it.

(2) Post all of your code, or at least all of the function you're having trouble with. If you really believe your code is so precious and secret that you can't let us see anything other than the 5 lines of code you think are relevant, at least make sure you're not including random snippets like the extra "end)" at the end of yours.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 07-02-12 at 07:09 PM.
Phanx is offline   Reply With Quote
Unread 07-01-12, 02:05 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,023
Originally Posted by Phanx View Post
(2) Modify your event handler code to explicitly check whether the fired event is PLAYER_REGEN_ENABLED before hiding the frame:

Code:
if event == "PLAYER_REGEN_DISABLED" then
	self:Show()
else
	self:Hide() 
end
Should be:
Code:
if event == "PLAYER_REGEN_DISABLED" then
	self:Show()
elseif event == "PLAYER_REGEN_ENABLED" then
	self:Hide() 
end
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
SDPhantom is offline   Reply With Quote
Unread 07-01-12, 04:35 AM   #4
SRCarebear
A Fallenroot Satyr
AddOn Compiler - Click to view compilations
Join Date: Mar 2009
Posts: 26
Thanks for the help both of you. I actually managed to figure it out late last night with a little bit of help, just as I went to bed. It works flawlessly now, thanks a lot.

Last edited by SRCarebear : 07-01-12 at 04:52 AM.
SRCarebear is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Making frame appear in combat. Hide out of combat.

Thread Tools
Display Modes

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