[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Wildcards
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Wildcards

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by 2009   (2 posts)  [Biography] bio
Date Thu 06 Mar 2008 09:12 PM (UTC)
Message
Hi,

I'm new to this whole scripting and was wondering if there was a way to have varying number of wildcards in the one trigger.

I know i can do this:

Trigger: ^(.*?) says (.*?)$
Input: Greg says hi tony

And i assume wildcards [1] is "Greg" and wirldcards [2] is "hi tony".
Is it at all possible to have each word after the "says" a seperate wildcard, where the number of words can vary?(i hope that came out right :S)

thnx
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 07 Mar 2008 03:51 AM (UTC)
Message
Not exactly as wildcards, because the wildcard numbers are assigned when the regular expressions is parsed for round brackets. However you can achieve it easily enough with a bit of scripting. For example:


<triggers>
  <trigger
   enabled="y"
   match="^(.*?) says (.*?)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
who = "%1"
said = "%2"

print ("speaker is " .. who)
print ("words are:")

for w in string.gmatch (said, "[%a%d]+") do
  print (w)
end -- for loop  
</send>
  </trigger>
</triggers>


See http://www.mushclient.com/pasting for how to copy and paste that example into the client.

On your test I saw this:


Greg says hi tony
speaker is Greg
words are:
hi
tony


Effectively I have used a Lua regular expression inside the script to break up what was said into words.

Another test:


Greg says this is a fine how do you do
speaker is Greg
words are:
this
is
a
fine
how
do
you
do


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by 2009   (2 posts)  [Biography] bio
Date Reply #2 on Fri 14 Mar 2008 05:07 AM (UTC)
Message
Thanks Nick.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,673 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]