AddEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
{{Needs_Checking|Varible args are being declared as strings to work, I think this is now inconsistent since all other varible references are not declared as strings anymore}
__NOTOC__  
__NOTOC__  
{{Server client function}}
{{Server client function}}

Revision as of 07:18, 9 September 2007

{{Needs_Checking|Varible args are being declared as strings to work, I think this is now inconsistent since all other varible references are not declared as strings anymore}


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