AddEventHandler: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__  
__NOTOC__  
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function will add an [[event]] handler. An event handler is a function that will be called when an event is triggered. See [[event system]] for more information on how the event system works.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool addEventHandler ( string name, element element, string handler )     
bool addEventHandler ( string eventName, element attachedTo, string functionName )     
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''eventName:''' The name of the event you want to attach the handler function to
 
*'''attachedTo:''' The [[element]] you wish to attach the handler to. Often this can be the root element.
===Optional Arguments===
*'''functionName:''' The name of the function you wish to call. This function should have the correct number of parameters defined for the event you are using.
{{OptionalArg}}
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
===Returns===
Returns ''true'' if blah, ''false'' otherwise.
Returns ''true'' if the event handler was attached successfully. Returns ''false'' if the event specified could not be found or the ''attachedTo'' [[element]] specified is invalid.


==Example==  
==Example==  
This example does...
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
-- Get the root map element
blabhalbalhb --abababa
rootElement = getRootElement ()
--This line does this...
-- Add an event handler to the onSpawnPointUse event (triggered when a player spawns)
mooo
addEventHandler ( "onSpawnpointUse", rootElement, "spawn" )
-- Define our handler function
function spawn( thePlayer )
-- Tell them in the chat box that they've spawned
outputChatBox ( "You've spawned!", thePlayer )
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Event_functions}}
{{Event_functions}}

Revision as of 23:44, 20 May 2006

This function will add an event handler. An event handler is a function that will be called when an event is triggered. See event system for more information on how the event system works.

Syntax

bool addEventHandler ( string eventName, element attachedTo, string functionName )    

Required Arguments

  • eventName: The name of the event you want to attach the handler function to
  • attachedTo: The element you wish to attach the handler to. Often this can be the root element.
  • functionName: The name of the function you wish to call. This function should have the correct number of parameters defined for the event you are using.

Returns

Returns true if the event handler was attached successfully. Returns false if the event specified could not be found or the attachedTo element specified is invalid.

Example

-- Get the root map element
rootElement = getRootElement ()
-- Add an event handler to the onSpawnPointUse event (triggered when a player spawns)
addEventHandler ( "onSpawnpointUse", rootElement, "spawn" )
-- Define our handler function
function spawn( thePlayer )
	-- Tell them in the chat box that they've spawned
	outputChatBox ( "You've spawned!", thePlayer )
end

See Also