[MudWalker] Trigger Scripting, help please

Michael Beatty proto
Mon Sep 13 14:58:44 PDT 2004


On Sep 13, 2004, at 5:03 PM, Tim burke wrote:

> I know this may sound like a really simple question, but I cant for
> the life of me figure out how to do this.  I want to have a trigger,
> be able to extract text from that trigger, and use it on the commnad.
>
> Example:
> Input:
> [name] has arrived.
> Output:
> say Hi [name], how are you?
>
>
> Obviously thats not what I would be doing with it, but if I had that
> much I can figure out the rest on my own.

Quick answer:

In the settings dialog, triggers group, input pane:
^(\w+) has arrived\.$

Output pane (Lua):
message( "greeting trigger fired -- remove this line if you like" )
send( "Hi " .. arg[1] .. ", how are you?" )


More detailed answer:

On the input pane, type:
^(\w+) has arrived\.$

Mudwalker uses perl-compatible regular expressions (pcre) for its input 
pattern patching.  See here for more information:
http://www.perldoc.com/perl5.8.0/pod/perlre.html

Here's a basic explanation:
^ and $ anchor tags.  They mean to anchor the pattern against the start 
and end of the input.
\w+ means one or more word characters.
The parens mean to extract the input matched by the pattern inside and 
put it in a special arg[n] variable.  The text matched by the first 
paren group goes into arg[1], the second into arg[2], etc.

So \w+ matches the name and the parens extract the name to the lua 
arg[1] variable.

On the output pane, you should be using Lua or Lua (in substitution).

Lua:
message( "greeting trigger fired -- remove this line if you like" )
send( "Hi " .. arg[1] .. ", how are you?" )

Lua (in substitution):
@@message( "greeting trigger fired -- remove this line if you like" )
Hi $(arg[1])$, how are you?


This sends a message to the MudWalker window (not the MUD!) that the 
trigger has been fired, and then sends the response string to the mud.  
In the Lua mode, the '..' operator joins two strings together (such as 
"Hi " and the matched name from the input) into one string.  In the Lua 
substitution mode, we use the $(arg[1])$ to substitute in a lua 
variable to the text stream sent to the MUD.

Note: The particular input pattern used above won't recognize names 
with more than one word, or names with punctuation in them.  Consider 
it an exercise for the reader.
-- 
Michael Beatty | proto at beattys.us




More information about the MudWalker mailing list