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 ➜ General ➜ if statement not working

if statement not working

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


Posted by Shady Stranger   USA  (45 posts)  Bio
Date Wed 05 Jan 2011 04:15 AM (UTC)

Amended on Wed 05 Jan 2011 04:30 AM (UTC) by Shady Stranger

Message
This script ignores the if statement and automatically sends the command after it even when if statement is false.


<triggers>
  <trigger
   enabled="y"
   match="* say*, &quot;* ok*&quot;"
   send_to="12"
   sequence="100"
  >
  <send>local name = %1
local match = %3

if name == match then
  Send ("say Pass")
end -- if
</send>
  </trigger>
</triggers>


The above is obviously the whole trigger.


local name = %1
local match = %3

if name == match then
  Send ("say Pass")
end -- if


I would actually like for this script to Send ("say Fail") if name does not equal match but am not sure if I should use "else" or not.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 05 Jan 2011 04:38 AM (UTC)
Message
You have to quote strings. Otherwise it substitutes:


name = Nick


Since the variable "Nick" won't exist, it will be nil, and then the if test:


if name == match then


... will fail (it will test "if name == nil").

So you need:


local name = "%1"
local match = "%3"


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #2 on Wed 05 Jan 2011 04:55 AM (UTC)

Amended on Wed 05 Jan 2011 04:56 AM (UTC) by Shady Stranger

Message
Thanks, that works perfect. Now another question. How do I get it to ignore case?


local name = "%1"
local match = "%3"

if match == name then
  Send ("say Pass")

else
  Send ("say Fail")

end


For example if Nick = %1 and nick = %3, how do I get that to be true?
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 05 Jan 2011 05:06 AM (UTC)
Message
Force them both to be either upper or lower case. There are two ways of doing this, both functionally equivalent:


if match:lower () == name:lower () then
  -- whatever
end -- if

-- or:

if string.lower (match) == string.lower (name) then
  -- whatever
end -- if



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #4 on Wed 05 Jan 2011 05:24 AM (UTC)
Message
I'm sorry to keep asking more questions but these things keep popping up. I really do appreciate the help.


* say*, "* ok*"


The point of this is to perform a certain command whenever the first wildcard is the same as the the third. This works great thanks to the help above but I have encountered a problem where some of the lines may look like this:


*** Nick says, "nick ok"


How do I ignore the "*** " when it happens but still have the script function normally when "*** " isn't present?

Thanks a bunch for the help.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 05 Jan 2011 05:59 AM (UTC)

Amended on Wed 05 Jan 2011 06:01 AM (UTC) by Nick Gammon

Message
First click on the "convert to regular expression" button. That will give you the same functionality but be a regexp instead.

Then at the start, replace the ^ it will have put there by:


^(?:\*\*\* )?


That is saying, look for 3 asterisks followed by a space, but the ? at the end makes it optional. The ?: inside the brackets make this a non-capturing group (that is, it won't become a wildcard).

Another syntax would be:


^(?:\*{3} ){0,1}


That is, 3 asterisks, and 0 to 1 lots of the whole group.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #6 on Wed 05 Jan 2011 06:26 AM (UTC)
Message
Thanks Nick! You're a great help and teacher.
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.


20,927 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.