WoW:Handling events: Difference between revisions

m
no edit summary
(fixed typo in example code)
mNo edit summary
Line 8: Line 8:
# self, a reference to the frame to which the script handler belongs
# self, a reference to the frame to which the script handler belongs
# event, the name of the event being fired
# event, the name of the event being fired
# The remaining event arguments are placed within the vararg expression (...), as well as in the arg1-arg9 variables (the later mechanic is deprecated and may be removed in the future). You can extract variables from the vararg expression by simply assigning it to your local variables: <code>local arg1, arg2, arg3 = ...;</code>
# The remaining event arguments are placed within the vararg expression (...), as well as in the arg1-arg9 variables (the latter mechanic is deprecated and will be removed in Cataclysm<ref name="deprecated">[http://forums.worldofwarcraft.com/thread.html?topicId=25626580975 Preparing for Cataclysm]</ref>). You can extract variables from the vararg expression by simply assigning it to your local variables: <code>local arg1, arg2, arg3 = ...;</code>
The addon's OnEvent script handler function should either handle the event, or call another addon function to handle the event.
The addon's OnEvent script handler function should either handle the event, or call another addon function to handle the event.


Line 98: Line 98:


== Notes ==
== Notes ==
* Avoid using the global this, event, and arg1-arg9 variables (which are generally deprecated). Instead, use the arguments passed to the OnEvent script handler.
* The global this, event, and argX variables are being removed in Cataclysm<ref name="deprecated"/>. Instead, use the arguments passed to the OnEvent script handler.


== Relevant API ==
== Relevant API ==
* [[API_CreateFrame|CreateFrame]]("widgetType"[, "name"[, parent[, "inherits"]]])
* [[API_CreateFrame|CreateFrame]]("widgetType"[, "name"[, parent[, "inherits"]]])
* frame:[[API_Frame_SetScript|SetScript]]("handlerType", func)
* frame:[[API_Frame_SetScript|SetScript]]("handlerType", func)
* frame:[[API_Frame_HookScript|HookScript]]("handlerType", func)
* frame:[[API_Frame_RegisterEvent|RegisterEvent]]("eventName") (and possibly frame:[[API_Frame_RegisterAllEvents|RegisterAllEvents]]() )
* frame:[[API_Frame_RegisterEvent|RegisterEvent]]("eventName") (and possibly frame:[[API_Frame_RegisterAllEvents|RegisterAllEvents]]() )
* frame:[[API_Frame_UnregisterEvent|UnregisterEvent]]("eventName") (and possibly frame:[[API_Frame_UnregisterAllEvents|UnregisterAllEvents]]() )
* frame:[[API_Frame_UnregisterEvent|UnregisterEvent]]("eventName") (and possibly frame:[[API_Frame_UnregisterAllEvents|UnregisterAllEvents]]() )
* [[Events (API)]], a listing of events you may subscribe to.
* [[Events (API)]], a listing of events you may subscribe to.
== References ==
{{reflist}}
Anonymous user