event handling

Post Reply
icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

event handling

Post by icesteruk »

Sorry for all the posting but currently redesigning my system and I've ran into a weird issue.. I copied and pasted one of my GMCP event handling things over and it seems it doesnt want to load right..

Everything (vairbale wise) is correct but I keep getting errors such as

object:<event handler function> function:<Settings>
<attempt to call a nil value>

in the 'Registered Event Handlers" I have gmcp.Char.Vitals & gmcp.Char.Status

the code is
Code: [show] | [select all] lua
function onChar( event )

status.class = gmcp.Char.Status.class
status.guild = gmcp.Char.Status.guild
status.city = gmcp.Char.Status.city
status.name = gmcp.Char.Status.name
status.race = gmcp.Char.Status.race
status.status = (gmcp.Char.Vitals.status:lower() == "living" and true or false)
end
When I put and run this in an Alias, it runs fine without errors long as I take out the function part

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: event handling

Post by Akaya »

Is your script name the same as your function name? Looks like the script name will need to be onChar.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: event handling

Post by icesteruk »

oh.. didn't know that.. But fixed it.. Thank you :)

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: event handling

Post by Jor'Mox »

An alternate strategy is to us the registerAnonymousEventHandler function to register an arbitrary function to be called when an event is raised.

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: event handling

Post by Omni »

Jor'Mox wrote:An alternate strategy is to us the registerAnonymousEventHandler function to register an arbitrary function to be called when an event is raised.
One issue with this is that you can't unregister, so if it starts erroring, it will keep firing and unless I'm missing something, you've no way to stop it.

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

Re: event handling

Post by Vadi »

Well, not until you fix the function in question or put 'if true then return end' right at the top of it.

Post Reply