Registered Event Handlers

Post Reply
Posts: 21
Joined: Mon Sep 14, 2009 1:23 am

Registered Event Handlers

Post by BrandNew »

So, I'm either not understanding the manual very well or it's not complete yet, but see how this goes.

If I add a registered event handler to a script, let's call it biggun, I can then raiseEvent(biggun, argument) inside of, say a trigger and it will then parse through that script.

There is also mention of doing something like myScript(event_name) but I don't really understand this example either. Is myScript the actual name of the script? Anyway, I hope my question comes across clearly and thanks in advance for the reply.

User avatar
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Registered Event Handlers

Post by Heiko »

script name:"onSmileEventHandler"
registered event handler list: "onSmile"

Code: Select all

function onSmileEventHandler( eventName )
	echo("\nevent handler for event onSmile called!\n");
raiseEvent("onSmile") will call this script and any other scripts that have registred event handlers for "onSmile".
If your events contains additional arguments, the event handler functions needs to be declared correctly to be able to be called.

User avatar
Posts: 4844
Joined: Sat Mar 14, 2009 3:13 pm

Re: Registered Event Handlers

Post by Vadi »

You need to have a

function biggun (...)

In your script with such a registered handler

Posts: 28
Joined: Sun May 10, 2009 5:04 am

Re: Registered Event Handlers

Post by Thylacine »

Just a note for future reference,

If you're passing arguments to an event handler (even more than one) you don't need ... as a parameter:

Code: Select all

function event(eventName, a, b, c)
    echo(a); echo(b); echo(c)
Then you can raiseEvent("myEvent", "wh", "a", "t") and have it printed to the screen. If you parse more than 4 parameters to raiseEvent the remainder get ignored (unless you use the arg table I guess). Note that the first argument for a handler is always the event name, if you don't need this (most of the time you wont), substitute it with a _ to save a little time. I.e;
function event( _, a, b, c)

Post Reply