Thread Tools Display Modes
04-11-09, 08:07 PM   #1
Din
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 14
Question "Correct" way to monitor custom events?

So, probably a stupid question, but is there a "correct" way to handle behavior dependent on custom events in oUF?

By which I mean, say for instance I want to tint the target frame's backdrop based on unit reaction. This obviously needs to be updated on a target change and also on (I think?) UNIT_FACTION. Should I just be directly registering for these events and handling the behavior in my own functions, or is there some sort of hook/register/postupdate system oUF has that I ought to be using?

Obviously if the thing I wanted to change was a text string I'd just use tags... and I briefly considered abusing the convenience of the tag system for these purposes but I'm guessing that's not a good idea.
  Reply With Quote
04-11-09, 09:34 PM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
It's pretty similar to how you would do it in the normal cases:
Code:
frame:RegisterEvent('EVENT1', myEventFunc)
frame:RegisterEvent('EVENT2', myEventFunc)

frame:UnregisterEvent('EVENT1', myEventFunc)
frame:UnregisterEvent('EVENT2', myEventFunc)
You can also do it without a function, but I wouldn't recommend doing that .
  Reply With Quote
04-11-09, 09:42 PM   #3
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
A slight side note which I forgot (it's soon 6AM here after all ):

The event system in oUF handles multiple event handlers on a single-event automatically. This behavior is very uncommon for add-ons to use. Mostly because you always have a split between the different systems.

Let's take the following code as an example:
Code:
frame:RegisterEvent('EVENT1', myFunc1)
frame:RegisterEvent('EVENT1', myFunc2)
This will work just fine, but the behavior you get is pretty uncommon (compared with how Dongle/Ace handles the events). When EVENT1 fires, both functions will be executed, as oUF converts EVENT1 into a metatable and "hides" the fact that there are multiple functions connected to it.

The reason it works this way is mostly because I wanted a simple and transparent way to register multiple handlers onto a single event, without removing the ability to call them all through the ordinary syntax.

This is also the reason why you should provide the handler when you unregister the event. You can get quite the unexpected behavior if you don't .
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » "Correct" way to monitor custom events?


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