Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Wildcards

Wildcards

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


Posted by 2009   (2 posts)  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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by 2009   (2 posts)  Bio
Date Reply #2 on Fri 14 Mar 2008 05:07 AM (UTC)
Message
Thanks Nick.
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.


19,251 views.

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

Go to topic:           Search the forum


[Go to top] top

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