I rewrote the wiki explanation for Custom events. Based on the parts I did not understand properly when trying to learn it. I hope it is now easier to understand and use.
http://wiki.esoui.com/AddOn_Quick_Qu...s.22_in_Lua.3F
Also, regarding wanting an example. Here is a small lib I wrote (in part to learn Event Programming). On every UI update it checks if the Camera Heading has been changed (wich can be important to identify what target is under the cursor).
First I set up a dummy UI Element to intercept the UIUpdate Event. This was copied from exterminatus group Leader. There is no other way (like an Event Manager event) to get notified of a new Frame.
Code:
<GuiXml>
<Controls>
<TopLevelControl name="UI_UpdateInterceptor" movable="false">
<Dimensions x="58" y="58" />
<Anchor point="CENTER" />
<OnUpdate>
LibHeadingChange.onUIUpdate()
</OnUpdate>
</TopLevelControl>
</Controls>
</GuiXml>
Code:
--Background variable to store the last heading the Event was raised against
local SavedHeading = nil
--A table containing the Events String Name
local CustomEventNames = { HeadingChanged = "CUSTOM_EVENT_CAMERA_HEADING_CHANGED" }
--The OnUpdate handler of the XML Dummy Element
local function onUIUpdate()
local currentHeading = GetPlayerCameraHeading()
--If the heading has changed since you last used it, raise the Custom Event in the Global CALLBACK_MANAGER instance
if (currentHeading ~= SavedHeading) then
CALLBACK_MANAGER:FireCallbacks(CustomEventNames.HeadingChanged, SavedHeading, currentHeading)
SavedHeading = currentHeading
end
end
--Explicit exposure of local function globally under the choosen namespace
--Especially needed for the UI Element that need it#s handler
LibHeadingChange = {
onUIUpdate = onUIUpdate,
eventHeadingChanged = CustomEventNames.HeadingChanged
}
return LibHeadingChange
Now if somebody wanted to do anything if the heading changed (and not on every other Update Event) he would just have to do this:
Code:
--Set up handler for Custom event
local CustomEventExampleHandeler (oldHeading, newHeading)
--Code to do something with those two parameters, or even just one of them
end
--registering the Callback
CALLBACK_MANAGER:RegisterCallback(LibHeadingChange.eventHeadingChanged, CustomEventExampleHandeler)