Regular Expressions

Posted by Terry on Sat 14 Jul 2007 08:55 PM — 5 posts, 24,068 views.

USA #0
In a mud I'm playing, there's an elevator that I use all the time. The syntax is 'press button <#>' where <#> is an integer from 0 to 6. I'm trying to set up an alias so all I have to do is type 'p<#>'. However, I only want it to trigger if the wildcard is an integer from 0-6. All I was able to figure out was:
^p(0|1|2|3|4|5|6)$
press button %1
For this alias, it wasn't that bad. But what I'm worried about is when I want to have a range of integers that is something like 0-500. Is there a way I can use a range of integers to mimic this?
Amended on Sat 14 Jul 2007 08:56 PM by Terry
Australia Forum Administrator #1
Well, you could have done:


^p([0-6])$


It gets a bit fiddly with larger numbers, so it would be easier to do "send to script" and in that do something like this:


if %1 >= 0 and %1 <= 44 then
  Send ("Press button %1")
else
  Note ("Button %1 out of range")
end -- if

USA #2
How exactly does the "send to script" feature work? do i have to write another file that it goes to? or do i just write the script code in the "Send:" box? I've always wondered that, and that's why I've never really used the feature :( I couldn't find documentation that specifically said -where- to put it. I only saw stuff that said -how-.
USA #3
Send to Script in an alias or trigger allows the Script itself to be placed in the box that you would normally place Send To World commands. You can also do it another method which is specifying a script subroutine, that is located in the script file for the world. This CAN be preferable depending on situations, but I, myself have never wanted a script file, I use plugins, and World Variables to transfer data around.

Laterzzz,
Onoitsu2
Australia Forum Administrator #4
See this post:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6030

There are examples of "send to script" with screen dumps.