Difference between revisions of "Event Handler"

From Legends of Aria Admin and Modding Wiki
Jump to: navigation, search
Line 1: Line 1:
 
DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT  
 
DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT  
 
DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT
 
DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT
 
+
== Definition ==
 
  An Event Handler is a function registered in a special way to be called when certain things (events) happen.
 
  An Event Handler is a function registered in a special way to be called when certain things (events) happen.
 
+
== Official Documentation ==
 
Official Events Documentation: [[http://shardsonline.com/lN2rwhz4jSVambqesEBZ/lua-reference/events.html Events]]
 
Official Events Documentation: [[http://shardsonline.com/lN2rwhz4jSVambqesEBZ/lua-reference/events.html Events]]
 
+
== Registering an EventHandler ==
* Registering a function as Event Handler in its general abstract form is:
+
* Registering a function as EventHandler in its general abstract form is:
 
  RegisterEventHandler( (EventType)mEvent, (string)mEventIdentifier, (function)mEventHandler)  
 
  RegisterEventHandler( (EventType)mEvent, (string)mEventIdentifier, (function)mEventHandler)  
  
Line 22: Line 22:
 
RegisterEventHandler(EventType.Timer, "MyCoolestTimer", HandleTick)
 
RegisterEventHandler(EventType.Timer, "MyCoolestTimer", HandleTick)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Explanation: This Registers the Function "HandleTick" as Handler for the Timer named "MyCoolestTimer", and it is called whenever this specific timer fires.
 +
E.G. <code>this:FireTimer("MyCoolestTimer")<code> would fire the timer and thus call the "HandleTick" function.
 +
You can optionally pass data to an event when triggering it and thus give this data to the Event Handler.
 +
E.G: in the last Ecample we could have called <code>this:FireTimer("MyCoolestTimer",{name="MyData",content="Stuff"})<code> which would pass a table to the timer and the handler. If the handler can handle this data depends on its definition. Also, some events pass default data to the handlers, it is necessary to know which events pass which data. You can find this information in the official documentation.
 +
  
  
  
 
[[Category:Drafts]]
 
[[Category:Drafts]]

Revision as of 16:43, 1 November 2016

DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT

Definition

An Event Handler is a function registered in a special way to be called when certain things (events) happen.

Official Documentation

Official Events Documentation: [Events]

Registering an EventHandler

  • Registering a function as EventHandler in its general abstract form is:
RegisterEventHandler( (EventType)mEvent, (string)mEventIdentifier, (function)mEventHandler) 

mEvent can be one of the following events:

EventType. + LoadedFromBackup, .Destroyed,  .CreatedObject,  .ModuleAttached,  
.Timer,  .Message,  .EnterView,  .LeaveView,  .RequestPickUp,  .RequestDrop,  
.RequestEquip,  .ContainerItemAdded,  .ContainerItemRemoved,  .ItemEquipped,  
.ItemUnequipped,  .StartMoving,  .Arrived,  .Use,  .PlayerSpeech,  
.ClientUserCommand,  .ClientObjectCommand,  .ClientTargetAnyObjResponse,  
.ClientTargetGameObjResponse,  .ClientTargetLocResponse,  .ContextMenuResponse,  
.DynamicWindowResponse,  .UserLogout,  .GlobalVarUpdateResult

Example:

RegisterEventHandler(EventType.Timer, "MyCoolestTimer", HandleTick)

Explanation: This Registers the Function "HandleTick" as Handler for the Timer named "MyCoolestTimer", and it is called whenever this specific timer fires. E.G. this:FireTimer("MyCoolestTimer") would fire the timer and thus call the "HandleTick" function. You can optionally pass data to an event when triggering it and thus give this data to the Event Handler. E.G: in the last Ecample we could have called this:FireTimer("MyCoolestTimer",{name="MyData",content="Stuff"}) which would pass a table to the timer and the handler. If the handler can handle this data depends on its definition. Also, some events pass default data to the handlers, it is necessary to know which events pass which data. You can find this information in the official documentation.