Difference between revisions of "Help/Trigger"

From DikuMUD Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
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. Best with a few examples:
+
super powerful but they can also be a bit tricky to use.  
 
 
 
Usage:
 
Usage:
 
   trigger <regexp> command
 
   trigger <regexp> command
  
Say for example, you want to do whatever the beastly Fido tells you to do. This
+
Best with a few examples. Say you want to do whatever the beastly Fido tells you to do.
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):
+
told you and will execute the command (the $ sign, i.e. the whole string between the
 +
parenthesis):
  
   {trigger obey /^the Beastly Fido tells you '(.+?)'/ $
+
   {trigger obey /^the Beastly Fido tells you '(.+?)'/ $}
  
Or if maybe, every time one of your friends leaves a room you'd like to  
+
Or if maybe, every time one of the city guards leave a room you'd like to say
"I love <friend>. Especially when <friend> leaves <direction>.". This is
+
"I love the cityguard. Especially when the guard leaves <direction>.". This is
 
how to do it:
 
how to do it:
  
   {value friends papi|city guard|fido}
+
   {trigger loveit /^The Cityguard leaves (.+?)\./ say I love it when the guard leaves. Especially when the guard leaves $1.}
   {trigger loveit /^(@friends)\sleaves (.+?)\.$/ say I love $1. Especially when $1 leaves $2.}
+
 
 +
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.}
  
You may notice this is written with Regular Expressions. If you're not familiar or want to learn more
+
This tool [https://regexr.com/ RegEx Reference] can help you design your triggers. Just
this site [https://regexr.com/ RegEx Reference] allows you to build triggers.
+
copy & paste some text from DikuMUD into the text field and begin to write your regular
 +
expression. It's an excellent tool :-)
 +
  
 
See also:
 
See also:

Latest revision as of 18:26, 22 September 2020

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 <regexp> command

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 (the $ sign, i.e. the whole string between the parenthesis):

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

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.}

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}