event help

Post Reply
Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

event help

Post by Caled »

Code: Select all

pstats = matches[4]
eqbal = matches[5]
-- Check if time to raise onEqbal --
if eqbalcheck == 1 then
    if eqbal == "eb" then
        if armb == "lr" then
            raiseEvent( "onEqbal" )
            echo( "    event was just raised" )
            eqbalcheck = 0
        end
    end
end
That script is in my prompt trigger. The trigger is matching correctly, the correct values are being stored in my variables, and the if statement is evaluating true at the correct times (the echo in there is for testing/debugging.)
From that, I assume the event is being successfully raised.

I don't know how to create a script that runs when that event is raised, though.

I click on 'scripts'
I click on 'Add'
I name it something
I put "onEqbal" into the 'Add user defined event handler' field.
I put:
echo( "You have all balance and are ready to go" )
into the script field.

The echo never gets displayed. After rereading the entry on raiseEvent in the Lua API section of the manual, I renamed the script to 'onEqbal', deleted the contents of the 'user defined event handler' field, and put the following into the scripts field:

Code: Select all

function onEqbal( onEqbal )
    echo( "You have eq and bal and armb - go go go!" )
end
That seemed wrong to me, and I tried several other variations of it, but I'm taking blind stabs at something I don't understand.

Please help...

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

Re: event help

Post by Heiko »

You need to add a script item that handles your event e.g. add new script "eventHandlerOnBalance"
In the script of this script item you declare the event handler function. The requirement is that this function is named after the script item name. In this example the event handler must be named:

Code: Select all

function eventHandlerOnBalance( eventName )
     echo( "the event handler of the event " .. eventName .. " has just been called" )
end
In case you raise your events with additional parameters the event handler would need to be declared with all those parameters + a variable for the event name as its first parameter.
Then you have to add "onBalance" (or the name you want to raise e.g. raise("onBalance")) to the list of event handlers of the eventHandlerOnBalance script item. That's it. Event handlers will get called after all triggers have been run. Events in Mudlet are very fast and efficent and should be used as much as possible.
There will be much more in the manual soon.
Until then have a look at the demo package AchaeaInlineMapDemoPackage_v3.zip I have posted in the scripts section. This makes use of an "onMap" event.

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: event help

Post by Caled »

Thanks for the replies. I was so close in the end, I just hadn't thought to press 'Enter' to commit the event handler to the list of handlers after typing it in. :oops:

Post Reply