[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]  General
. . -> [Subject]  If/then statements with strings
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

If/then statements with strings

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


Posted by Ivalos   (1 post)  [Biography] bio
Date Thu 05 Aug 2010 08:05 PM (UTC)
Message
Right now, I have a trigger for my prompt that makes me sip/etc.
I'm trying to make my character stand if he's ever prone, and I got this far:

Trigger: ^\(h: (1?[0-9][0-9])% m: (1?[0-9][0-9])%\) [(p?)(e?b?c?x?s?)]$

SetVariable ("prone", "%3")
if @prone == 'p' then
 Send("handspring")
end


and that's not working. I'm worthless at coding.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Thu 05 Aug 2010 08:17 PM (UTC)
Message
What exactly do you mean by "not working"? What kind of error message are you getting? etc.

Try: GetVariable("prone") instead of @prone. If memory serves, @<var> substitutions are done only once, at the entrance of the script, so since you set the variable you can't use @prone.

Or, try: if "%3" == 'p'

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Thu 05 Aug 2010 08:17 PM (UTC)

Amended on Thu 05 Aug 2010 08:20 PM (UTC) by Twisol

Message
(EDIT: Haley-ninja'd :( )

You've hit a pretty common gotcha, actually. The Send code is pre-processed before it's run as Lua code. The @var and %wildcard syntax is not part of Lua, and MUSHclient replaces them with their true values before running the code. So in your code, @prone is actually retrieved before you set it.

Just use GetVariable("prone") or "%3" instead of @prone:

SetVariable ("prone", "%3")
if "%3" == 'p' then
 Send("handspring")
end

-- Or this:

SetVariable ("prone", "%3")
if GetVariable("prone") == 'p' then
 Send("handspring")
end



There's also another problem in your code: @ and % identifiers are inserted directly into the code, so if we assume that @prone does contain the letter p, it would look like this before going into Lua:

SetVariable ("prone", "%3")
if p == 'p' then
 Send("handspring")
end


It looks like p is a variable, not a string. So you need to quote @ and % identifiers yourself if you're going to use them as strings:

SetVariable ("prone", "%3")
if "%3" == 'p' then
 Send("handspring")
end


Final nitpick: Make sure you use double quotes "" instead of single quotes '' when quoting the @/% identifiers. If a variable contains a double quote, MUSHclient will escape it for you so it doesn't cause a script error (because Lua will think the string ended early). I don't believe it does the same with single quotes, so you need to make sure you use the doubles!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 05 Aug 2010 09:36 PM (UTC)
Message
Twisol said:

Final nitpick: Make sure you use double quotes "" instead of single quotes '' when quoting the @/% identifiers. If a variable contains a double quote, MUSHclient will escape it for you so it doesn't cause a script error (because Lua will think the string ended early). I don't believe it does the same with single quotes, so you need to make sure you use the doubles!


Twisol is right - only double-quotes are fixed up.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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,139 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]