RemoveEventHandler: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
LordAzamath (talk | contribs) |
||
Line 17: | Line 17: | ||
==Example== | ==Example== | ||
This | This example shows how to toggle a message on/off a screen with a command. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
--add an | |||
function drawText() -- A function to draw the text we want | |||
dxDrawText(text, 10,100) -- creates a dx text 10 pixels from left, 100 from top of the screen | |||
end | |||
function doText(command, ...) | |||
if command == "starttext" then -- if player wrote /starttext | |||
text = table.concat({...}," ") -- then we retrieve the text | |||
func = addEventHandler -- and since addEventHandler and removeEventHandler's syntax is the same, we just define the function we use later | |||
elseif command == "stoptext" then | |||
func = removeEventHandler -- this time we use removeEventHandler | |||
end | |||
func("onClientRender", getRootElement(),drawText) -- and varying on which one we chose up, we either add an event handler to show the text or remove it to stop drawing dx text. | |||
end | |||
addCommandHandler("starttext", doText) -- add two command handlers to doText function | |||
addCommandHandler("stoptext", doText) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Event_functions}} | {{Event_functions}} | ||
Revision as of 09:02, 15 May 2009
This functions removes a handler function from an event, so that the function is not called anymore when the event is triggered. See event system for more information on how the event system works.
Syntax
bool removeEventHandler ( string eventName, element attachedTo, function functionVar )
Required Arguments
- eventName: The name of the event you want to detach the handler function from.
- attachedTo: The element the handler was attached to.
- functionVar: The handler function that was attached.
Returns
Returns true if the event handler was removed successfully. Returns false if the specified event handler could not be found or invalid parameters were passed.
Example
This example shows how to toggle a message on/off a screen with a command.
function drawText() -- A function to draw the text we want dxDrawText(text, 10,100) -- creates a dx text 10 pixels from left, 100 from top of the screen end function doText(command, ...) if command == "starttext" then -- if player wrote /starttext text = table.concat({...}," ") -- then we retrieve the text func = addEventHandler -- and since addEventHandler and removeEventHandler's syntax is the same, we just define the function we use later elseif command == "stoptext" then func = removeEventHandler -- this time we use removeEventHandler end func("onClientRender", getRootElement(),drawText) -- and varying on which one we chose up, we either add an event handler to show the text or remove it to stop drawing dx text. end addCommandHandler("starttext", doText) -- add two command handlers to doText function addCommandHandler("stoptext", doText)
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled