AddEvent: Difference between revisions
Jump to navigation
Jump to search
(Removed references to obsolete parameters) |
|||
Line 8: | Line 8: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''eventName:''' The name of the event you wish to create | *'''eventName:''' The name of the event you wish to create. | ||
===Returns=== | ===Returns=== | ||
Line 17: | Line 16: | ||
This example will define a new event called ''onSpecialEvent''. | This example will define a new event called ''onSpecialEvent''. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Get the root | -- Get the global root element | ||
rootElement = getRootElement () | rootElement = getRootElement () | ||
-- Add a new event called onSpecialEvent | -- Add a new event called onSpecialEvent | ||
addEvent ( "onSpecialEvent" ) | addEvent ( "onSpecialEvent" ) | ||
-- Define our handler function | -- Define our handler function, that takes a "text" parameter | ||
function specialEventHandler ( text ) | function specialEventHandler ( text ) | ||
outputChatBox ( text ) | outputChatBox ( text ) | ||
end | end | ||
-- Add | |||
-- Add it as a handler for our event | |||
addEventHandler ( "onSpecialEvent", rootElement, specialEventHandler ) | addEventHandler ( "onSpecialEvent", rootElement, specialEventHandler ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 15:32, 30 July 2007
This function allows you to register a custom event. Custom events function exactly like the built in events. See event system for more information on the event system.
Syntax
bool addEvent ( string eventName )
Required Arguments
- eventName: The name of the event you wish to create.
Returns
Returns true if the event was added successfully, false otherwise.
Example
This example will define a new event called onSpecialEvent.
-- Get the global root element rootElement = getRootElement () -- Add a new event called onSpecialEvent addEvent ( "onSpecialEvent" ) -- Define our handler function, that takes a "text" parameter function specialEventHandler ( text ) outputChatBox ( text ) end -- Add it as a handler for our event addEventHandler ( "onSpecialEvent", rootElement, specialEventHandler )
You can then trigger this event later on using:
triggerEvent ( "onSpecialEvent", rootElement, "test" )
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled