Thread Tools Display Modes
02-17-12, 07:59 PM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Code for a kgPanel

If event "WHATEVER_THE_EVENT_MAY_BE" then
MyPanel:Show()
end

How do i code MyPanel to hide again after, say, 10 seconds of the event firing?

Any help would be greatly appreciated!!!
__________________
__________________
  Reply With Quote
02-17-12, 08:16 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You'll need to give it an OnUpdate script.

http://www.wowpedia.org/UIHANDLER_OnUpdate
http://www.wowpedia.org/Using_OnUpdate_correctly
__________________
"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
02-20-12, 03:44 AM   #3
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Hia. Thanks for your reply. Although I'm making quite a bit of progress with learning how to script, those links havnt helped much. I understand the principle, I just can't seem to put it into practice .

Would anyone be able to give me a wee hand with an example?

Thanks in advance and sorry to bother!
__________________
__________________
  Reply With Quote
02-20-12, 05:10 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm not that familiar with kgPanels, but presumably you're registering for events in an OnLoad script for the panel:

Code:
self:RegisterEvent("WHATEVER_THE_EVENT_MAY_BE")
In the same place, make sure your panel is hidden, if you're not already:

Code:
self:Hide()
self:RegisterEvent("WHATEVER_THE_EVENT_MAY_BE")
And set up a counter for keeping track of the time:

Code:
self.counter = 0
self:Hide()
self:RegisterEvent("WHATEVER_THE_EVENT_MAY_BE")
Then set an OnUpdate script for the panel. OnUpdate scripts are run every time a new video frame is drawn (10-100 or more times per second, depending on your hardware capability and video settings), but only when the frame they are set on is shown on the screen. So, setting the frame to hidden immediately makes sure the script won't be running.

In this case, we want the OnUpdate script to count to 10 seconds, and then hide the frame. Assuming kgPanels uses the standard argument names, your OnUpdate script will receive an argument named elapsed, which contains the amount of time that has elapsed since the last OnUpdate run. You'll use the counter we set up earlier to keep a running total of all these tiny increments of time.

Code:

-- Make sure you have kgPanels r403 or higher; this is required
-- because of a variable naming issue in older versions.
self.counter = self.counter + elapsed
if self.counter >= 10 then
     -- 10 seconds have passed!
     self:Hide()
end
Now, you'll need to modify your OnEvent script a little bit to use the counter:

Code:
if event == "WHATEVER_THE_EVENT_MAY_BE" then
    -- First, reset the counter:
    self.counter = 0
    -- Then, show the frame:
    self:Show()
end
It's important to reset the counter first. Otherwise, it will still be at 10 when you show the panel, so it will immediately get hidden again.

I chose to reset the counter in the OnEvent script, instead of in the OnUpdate script (eg. right after you hide the frame) so that if the event fires again before the 10 seconds are up, it resets the counter and keeps the panel visible for 10 seconds after the last event, not the first one. This may not be relevant for your event (eg. PLAYER_LEVEL_UP) but even if it's not, it doesn't hurt anything to do it this way.

Last edited by Phanx : 02-27-12 at 12:48 AM.
  Reply With Quote
02-20-12, 02:42 PM   #5
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Thanks so much for that reply mate. I'm learning more and more every day.

I don't think kgPanels is allowing it though

I set it up exactly as instructed, but when the panel shows, the frame rate drops by about 3 quarters.

Through trial and error, I've narrowed it down to 'elapsed'. As soon as I add that word, the FPS plummets. I take it away and it shoots back up again.

Does that symptom suggest that I've maybe done something wrong or do you think that it is a kgPanel limitation after all?

I'm surprised, I'd always thought that kgPanels didn't have any code limitations. Perhaps that is naive of me.
__________________
__________________
  Reply With Quote
02-20-12, 07:30 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
After looking at the code of kgPanels, I see the problem. Rather than using the standard variable name "elapsed", the author of kgPanels chose to use the variable name "time", which in addition to breaking with convention also overrides the global function name "time", preventing it from being used inside panels' OnUpdate scripts.

This means that the code I previously posted was looking up a global variable "elapsed" with every frame, which is slower in general, and is probably generating tons of errors if it's nil or contains some value type other than a number.

Replace "elapsed" with "time" in the OnUpdate script I posted before, and it should work. I'll also update the code in my post.

I also posted a bug report ticket on kgPanels, but given the number of outstanding tickets, I'm not hopeful it will be addressed anytime soon, if ever.
  Reply With Quote
02-21-12, 09:44 AM   #7
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
That's great Phanx thanks. I'm surprised you went to the effort to do that.

I know of the addons that you've authored so thanks for taking what little spare, spare time you have to check into this. I'll give it a try and let you know.
__________________
__________________
  Reply With Quote
02-26-12, 02:06 PM   #8
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,364
Originally Posted by Phanx View Post
I also posted a bug report ticket on kgPanels, but given the number of outstanding tickets, I'm not hopeful it will be addressed anytime soon, if ever.
It actually DID work, and pretty quickly too. Your ticket was filed on 2/21 and the update was released on 2/21 also.

You have to get the latest Alpha version (r403 from their WoWAce page) and I don't know how that part works but this:
r403
Date: 2/21/2012 6:53:39 PM
Type: Alpha
------------------------------------------------------------------------
r403 | kagaro | 2012-02-21 23:52:27 +0000 (Tue, 21 Feb 2012) | 2 lines
Changed paths:
M /trunk/kgPanels.lua

fix ticket #41
passed in variable is now called elapsed instead of time.
is the update log from the Curse Client about it.
__________________
Ahhhh, the vagueries of the aging mind. Wait.... What was I saying?


Carbonite <----- GitHub main module (Maps ONLY) download link. The other modules are also available on GitHub.
Carbonite-CLASSIC<----- GitHub link to Carbonite Classic. Thanks to ircdirk for this!

Last edited by jeffy162 : 02-26-12 at 02:11 PM.
  Reply With Quote
02-27-12, 12:47 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Edited the code in my other post again.

Aanson, if you update kgPanels, don't forget to change "time" back to "elapsed" in the OnUpdate script.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Code for a kgPanel


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