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 ➜ Problem with ~= operator

Problem with ~= operator

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


Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Mon 11 Aug 2008 02:02 AM (UTC)
Message
Alright, I'm trying to create a simple trigger that will take away a given defense when the person who puts it up is the person I am targeting. The trigger fires, however, the secondary clause doesn't seem to want to evaluate itself. Therefore, I have come here--again--to see what rookie mistake I have made. Here is the code:




if %1 == @tar then
   ColourNote ("red", "black", "<<<SHIELDED-RAZE-SHIELDED>>>")
   DoAfter (3, "raze @tar")
elseif %1 ~= @tar then
   ColourNote ("blue", "black", "<<<IS THERE DANGER?>>>")
end--if



I tried to change the "elseif" to just "else" but all it would return is:



Compile error
World: Lusternia
Immediate execution
[string "Trigger: "]:4: '=' expected near '~='


Any suggestions?

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #1 on Mon 11 Aug 2008 02:13 AM (UTC)
Message
I am assuming your %1 exists out of multiple words, which would mean it would look like 'if multiple words ~= contents_of_tar then'.

The best solution is to make sure both %1 and @tar have quotes around them like "%1" and "@tar".

Good luck.
Top

Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Reply #2 on Mon 11 Aug 2008 02:34 AM (UTC)
Message
Yeah, someone just helped me out. As for the wildcard, this is one instance where it is actually only one word. Anyhow, thanks for the help. Your reply was actually the same solution I got from a friend. Thanks again!

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Beale   (35 posts)  Bio
Date Reply #3 on Fri 15 Aug 2008 01:37 AM (UTC)

Amended on Fri 15 Aug 2008 01:49 AM (UTC) by Beale

Message
Incidentally, I found " to be far too common a character about, and tend to use the more robust Lua quotes for stuff like pattern matches and variables:
[[%1]], [[@tar]], [[quoted string]]

This type of quote allows newlines and basically every character sequence except the terminating ]]. (I think.)
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.


13,846 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.