Difference between revisions of "Help/Trigger"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the code)
 
Line 1: Line 1:
 
= Trigger =
 
= Trigger =
  
−
If you're playing DikuMUD with the web-client there is built-in support for  
+
If you're playing DikuMUD with the web-client there is built-in support for
 
triggers. A trigger is useful for sending commands to the MUD when certain
 
triggers. A trigger is useful for sending commands to the MUD when certain
 
text appears on your screen.
 
text appears on your screen.
  
 
Triggers in the web-client are based on Java Script Regular Expressions.They're
 
Triggers in the web-client are based on Java Script Regular Expressions.They're
−
super powerful but they can also be a bit tricky to use.  
+
super powerful but they can also be a bit tricky to use.
 
Usage:
 
Usage:
−
   trigger <regexp> command
+
  trigger                              (lists your triggers)
 +
   trigger <name> /<regexp>/ <commands>
 +
  trigger <name>                      (removes the trigger)
 +
 
 +
The name is one word of up to 12 letters. In the commands, $1 is the text
 +
caught by the first pair of parentheses in the regexp, $2 by the second, and
 +
so on; $0 is all the text that matched. Upper and lower case don't matter.
 +
Several commands can be given, separated by ;. Your triggers are kept with your
 +
character, up to 25 of them.
  
 
Best with a few examples. Say you want to do whatever the beastly Fido tells you to do.
 
Best with a few examples. Say you want to do whatever the beastly Fido tells you to do.
 
This command will trigger on the tell from beastly Fido, will extract what the dog
 
This command will trigger on the tell from beastly Fido, will extract what the dog
−
told you and will execute the command (the $ sign, i.e. the whole string between the
+
told you and will execute the command ($1, i.e. the whole string between the
 
parenthesis):
 
parenthesis):
  
−
   {trigger obey /^the Beastly Fido tells you '(.+?)'/ $}
+
   {trigger obey /^the Beastly Fido tells you '(.+?)'/ $1}
  
 
Or if maybe, every time one of the city guards leave a room you'd like to say
 
Or if maybe, every time one of the city guards leave a room you'd like to say
Line 28: Line 36:
 
   {trigger loveit /^(@friends)\sleaves (.+?)\./ say I love it when $1 leaves. Especially when $1 leaves $2.}
 
   {trigger loveit /^(@friends)\sleaves (.+?)\./ say I love it when $1 leaves. Especially when $1 leaves $2.}
  
−
This tool [https://regexr.com/ RegEx Reference] can help you design your triggers. Just  
+
If triggers fire more than five times in a second (two triggers answering each
−
copy & paste some text from DikuMUD into the text field and begin to write your regular  
+
other, say), they pause for a second.
 +
 
 +
This tool [https://regexr.com/ RegEx Reference] can help you design your triggers. Just
 +
copy & paste some text from DikuMUD into the text field and begin to write your regular
 
expression. It's an excellent tool :-)
 
expression. It's an excellent tool :-)
−
+
 
  
 
See also:
 
See also:

Latest revision as of 21:28, 14 November 2026

Trigger

If you're playing DikuMUD with the web-client there is built-in support for triggers. A trigger is useful for sending commands to the MUD when certain text appears on your screen.

Triggers in the web-client are based on Java Script Regular Expressions.They're super powerful but they can also be a bit tricky to use. Usage:

 trigger                              (lists your triggers)
 trigger <name> /<regexp>/ <commands>
 trigger <name>                       (removes the trigger)

The name is one word of up to 12 letters. In the commands, $1 is the text caught by the first pair of parentheses in the regexp, $2 by the second, and so on; $0 is all the text that matched. Upper and lower case don't matter. Several commands can be given, separated by ;. Your triggers are kept with your character, up to 25 of them.

Best with a few examples. Say you want to do whatever the beastly Fido tells you to do. This command will trigger on the tell from beastly Fido, will extract what the dog told you and will execute the command ($1, i.e. the whole string between the parenthesis):

 {trigger obey /^the Beastly Fido tells you '(.+?)'/ $1}

Or if maybe, every time one of the city guards leave a room you'd like to say "I love the cityguard. Especially when the guard leaves <direction>.". This is how to do it:

 {trigger loveit /^The Cityguard leaves (.+?)\./ say I love it when the guard leaves. Especially when the guard leaves $1.}

If you want to add to that the use of variables, you can do like this:

 {variable friends papi|the cityguard|the beastly fido}
 {trigger loveit /^(@friends)\sleaves (.+?)\./ say I love it when $1 leaves. Especially when $1 leaves $2.}

If triggers fire more than five times in a second (two triggers answering each other, say), they pause for a second.

This tool RegEx Reference can help you design your triggers. Just copy & paste some text from DikuMUD into the text field and begin to write your regular expression. It's an excellent tool :-)


See also:

 {Help bot}
 {Help variable}
 {Help alias}