START OF DOCUMENT PREVIOUS PAGE
Copyright © 1995 Robert M. Free - publishing rights reserved
MUTT(tm) and MUTTER(tm) are trademarks of Robert M. Free

This document may be freely copied and distributed, provided that: this copyright notice is included, the entire body of text is included, and the textual content of this document is unchanged.

For written permission to use portions of this document in other publications, send email to bfree@graphcomp.com.


[] Defining and Using Triggers

Triggers are strings used to compare against incoming text. When enabled, they are bound to a script, which is executed when the trigger text is encountered in output stream from the mud host.


Trigger Usage

Several steps are required in using triggers:

  • Define a trigger string - described below.
  • Define a script to be executed when the trigger is tripped.
  • Enable the trigger through either the "trigger" or wait commands.


    Defining a Trigger

    Triggers are defined within the "[Triggers]" section of a script file.

    The trigger format is as follows:

    label = string, case_flag

    "label" is a unique trigger name with 16 characters or less and may not include spaces. "string" is the trigger string that is used for seeking matches. "case_flag" is 1 for case-sensitive matching; otherwise 0.

    Note: increasing the number of active triggers will gradually slow MUTT(tm)'s response time.

    MUTT(tm) Lite does not support regular expressions in "string".


    An Example

    Since triggers are so frequently used in battle muds, the following sample script is included to demonstrate how a script could be used to automate certain battle actions. In this case, we are hunting critters and preparing them to be eaten.

    
    [Variables]
    object      = str, 128
    
    [Scripts]
    init        = wait( name_trg, 20, do_name, fail_start );
    do_name     = say( CHARACTER ); wait( pass_trg, 30, do_pass, fail_start );
    do_pass     = say( PASSWORD ); if( CREATE ) say( PASSWORD ); do( start ) else do( start );
    start       = trigger( killed_trg, killed );
    fail_start  = popup( "Failed init" );
    
    killed      = setword( object, TRIGGER_LINE, -1 ); clean( object, "." ); do( corpse );
    corpse      = if( findstr( object, "owl", 0 ) ) do( pluck ) else do( skin );
    skin        = say( "skin ", object ); do( gut );
    pluck       = say( "pluck ", object ); do( gut );
    gut         = say( "gut ", object ); do( carve );
    carve       = say( "carve ", object ); say( "eat meat\nbury corpse" );
    
    [Triggers]
    name_trg    = "name:", 0
    pass_trg    = "Password:", 0
    killed_trg  = "killed", 0
    
    

    Overview

    The above example exhibits two common uses of triggers. The first is used defining a login script, the second to perform a series of operations based on a single trigger.

    First, a string variable, 128 bytes long, is defined in the [Variables] section. This will be used to act on the subject of the trigger.

    Next, several scripts are definined in the [Scripts] section. Of special note is "init": the "init" script is a special script that is automatically executed when first connecting to a mud host.

    Finally the triggers are defined. The first two, "name_trg" and "pass_trg" are used for handling the login script. The third is a trigger that will be used during game playing.

    Login

    The init script enables the "name_trg" trigger through the "wait" command. "wait" will enable the trigger as a one-shot event; if the trigger string is encountered before the 20 second timeout, the "do_name" script is executed; otherwise the "fail_start" script is run.

    When the string "name:" is encountered, "do_name" executes, which in turn sends the character name and then posts a wait on the "pass_trg" trigger. If this suucceeds, the "do_pass" script is run.

    The "do_pass" script sends the password; if the session was started by pressing the "New" button, then the script sends the password a second time. Then it runs the "start" script, which enables the "killed_trg" trigger.

    Battle Triggers

    Several triggers may be enabled in the "start" script; this example only demonstrates one.

    When the the string "killed" is encountered, the "killed" script is executed. This script uses "setword" to grab the last word of the trigger line and saves it in the variable "object". It then strips punctuation from the word and calls the "corpse" script.

    The "corpse" script checks to see if the object is an owl, if so, it proceeds to pluck it; otherwise it skins it. Next it is gutted, carved, eaten and the carcass buried.


    NEXT PAGE Defining and Using HotKeys


    For more information on MUTT(tm), email mutt@graphcomp.com.