### Trigger Definition

A Trigger allows the MudMagic client to automatically execute a command or series of command based on the output of your screen. So if you want to congratulate someone everytime they level, you can create a trigger to automatically chat a congratulations when the string 'Kelmar has reached level 20' is viewed. To create this type of trigger, a little regular expression is required.

Trigger actions can be any of the following:
- Text output
- MudMagic BASIC scripting output
- Python scripting output
- Play a sound file
- Popup a message box

All alias events use PCRE (perl compatible regular expression). What this means, is if you create an alias called just: test, then if you input anything on the command line that contains the word "test" in it, the alias will trigger. For example, the following This isatest would trigger an alias with a Statement setting of "test". Thus, make sure to check your PCRE settings. What you want to use for just a 'test' input statement would actually be: ^test. Since the Statement trigger is PCRE based, you can pass arguments through to a back end script - or just output plain text for the simpler aliases.

A full pattern match with Regex for an event such as: Flicker tells you 'Hi there'. would appear as:

      Name:   Automatic Reply
      Statement: (.*) tells you '(.*)'.
      Action: (Script) BASIC:

          print "tell $1 Sorry I missed your message, I've written it down though"
          print "note to Kyndig;note subject Missed Message from $1"
          print "note + $2"
          print "note post"

The above example trigger will execute when the pattern is matched. If you read it carefully, you will see that a reply message is sent back to Flicker and a note is posted to Kyndig that a message was missed. The content of the note is the message that Flicker sent (or $2 - which is the second argument of the caught pattern )
For help in Regular Expression usage for catching a trigger, visit: http://perldoc.perl.org/perlre.html

### Trigger Editing

To edit a Trigger, you fill out the Name, Statement, and select the action.

The Trigger: is either a basic line pattern match: has entered the game or a regular expression: (.*) has entered the game.

### Scope of Triggers

Triggers can be stored as Local game triggers, or Global world triggers. Local game triggers are only available for that specific game you are connected to - whereas Global world triggers are available to any game you are connected to. For Global Trigger editing - visit: Setting -> Global Settings -> Actions -> Triggers. To edit your local game alias, visit: Profile -> Actions -> Triggers when connected to a game.

All triggers are stored and saved on a per-game basis. So each game has its own unique triggers system. Global triggers are the only exception to this rule - where they are available to any game. Triggers can also be imported/exported on a game-by-game basis through the Import/Export feature.

### Scripting Support

Triggers can use either Python or the MudMagic BASIC scripting language. For more assistance in BASIC and Python scripting, see: Scripting to the left.

### Trigger Examples

Triggers allow you to react automatically to text that comes from the MUD. This reaction can be of two forms: sending something to the MUD in reply, or there may be no direct interaction with the MUD, but something might be printed in the screen, or something else done to call your attention. With the use of Perl PCRE, you can pass arguments to the MudMagic command interpreter to perform some BASIC script support if desired.

        Example 1:
    	Name: Someone Died
    	Statement:  has been killed in battle
    	Action: Text
    	--------------------
    	chat comforts

The above example will output to your client: chat comforts If the line: 'has been killed in battle' appears on your client screen.

       Example 2:
            Name: <target> has died
            Statement: (.*) has been killed in battle
    	Action: (Script) BASIC
    	---------------------
    	print "restore $1"
    	print "chat comforts $1"

The above trigger is like the first example, except it uses regular express to store arguments which can be used in the Mudmagic BASIC command interpreter. If the message: Kyndig has been killed in battle appears on your screen the following will be sent:

restore Kyndig chat comforts Kyndig

Copyright © 2004-02-26 MudMagic.Com