AddEvent: Difference between revisions
Jump to navigation
Jump to search
(Needs checking) |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
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. | 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. | ||
Line 5: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool addEvent ( string eventName | bool addEvent ( string eventName ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 22: | Line 21: | ||
-- Add a new event called onSpecialEvent that has one parameter 'text' | -- Add a new event called onSpecialEvent that has one parameter 'text' | ||
addEvent ( "onSpecialEvent | addEvent ( "onSpecialEvent" ) | ||
-- Add an event handler | -- Add an event handler |
Revision as of 11:02, 29 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
- arguments: A string of comma seperated variable names indicating the arguments your event takes. These names are used for event handlers that are coded in the map structure. For example "message, playerName".
Returns
Returns true if the event was added successfully, false otherwise.
Example
This example will define a new event called onSpecialEvent.
-- Get the root map element rootElement = getRootElement () -- Add a new event called onSpecialEvent that has one parameter 'text' addEvent ( "onSpecialEvent" ) -- Add an event handler addEventHandler ( "onSpecialEvent", rootElement, "specialEventHandler" ) -- Define our handler function function specialEventHandler ( text ) outputChatBox ( text ) end
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