AddEvent: Difference between revisions
Jump to navigation
Jump to search
m (Added template, sections, improved example) |
mNo edit summary |
||
Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool addEvent ( string eventName ) | bool addEvent ( string eventName ) | ||
Line 14: | Line 13: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the event was added successfully, ''false'' otherwise. | Returns ''true'' if the event was added successfully, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example will define a new event called ''onSpecialEvent''. | This example will define a new event called ''onSpecialEvent''. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 38: | Line 35: | ||
This will cause the handler to be triggered, so "test" will be output to the chatbox. | This will cause the handler to be triggered, so "test" will be output to the chatbox. | ||
==See Also== | ==See Also== | ||
{{Event functions}} | {{Event functions}} |
Revision as of 14:43, 21 August 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.
-- Add a new event called onSpecialEvent addEvent ( "onSpecialEvent" ) -- Define our handler function, that takes a "text" parameter and outputs it to the chatbox function specialEventHandler ( text ) outputChatBox ( text ) end -- Add it as a handler for our event addEventHandler ( "onSpecialEvent", getRootElement(), specialEventHandler )
You can then trigger this event later on using:
triggerEvent ( "onSpecialEvent", getRootElement(), "test" )
This will cause the handler to be triggered, so "test" will be output to the chatbox.
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled