API RegisterEvent: Difference between revisions

From Vendetta Lua
Jump to navigationJump to search
split
 
No edit summary
Line 1: Line 1:
=== RegisterEvent ===
=== RegisterEvent ===
'''Definition:'''
'''Definition:'''
RegisterEvent({func OnEvent}, string eventtype) -> nil
RegisterEvent(object eventhandler, string eventtype) -> nil
<br>
<br>
'''Description:'''<br>
'''Description:'''<br>
hook up object to event. the obect is a table with a method called OnEvent that is called when the event is triggered
Hook up object to event. The object is a function or a table with a method called OnEvent or the name of the event. See [[Eventtype#Introduction|Event Intro]]
<br>
<br>
'''Arguments:'''<br>
'''Arguments:'''<br>
'''OnEvent''' function to call when event is triggered<br>
''eventhandler'' object to register with event<br>
''eventtype'' [[eventtype]]
''eventtype'' [[eventtype]]
<br>
<br>
'''Example:'''<br>
'''Example:'''<br>
obj = {}
see [[Eventtype#Introduction|Event Intro]]
-- create method in above created table that prints out the name of the event and the data passed to it
function obj:OnEvent(event, ...) print(event) print(...) end
-- Register the event
RegisterEvent(obj, "TEST_EVENT")
-- trigger the event and pass the string "test" to it
ProcessEvent("TEST_EVENT", "test")
-- which should output:
-- TEST_EVENT
-- test
</source>
<br>
<br>

Revision as of 05:56, 17 February 2009

RegisterEvent

Definition: RegisterEvent(object eventhandler, string eventtype) -> nil
Description:
Hook up object to event. The object is a function or a table with a method called OnEvent or the name of the event. See Event Intro
Arguments:
eventhandler object to register with event
eventtype eventtype
Example:
see Event Intro