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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Apostrophes in Variables sent to script
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Apostrophes in Variables sent to script

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Plyth   (5 posts)  [Biography] bio
Date Tue 11 Nov 2008 04:47 PM (UTC)  quote  ]
Message
Okay, so I have a trigger set up so that when someone sends me a tell to MIND SENSE <target>, I will perform that action and reply to them with the target's location. This works perfectly except for in situations where the target's location has apostrophes in the title. For example, one person I mind sensed was located at Entryway to Merchant's Quarter. I store that into a variable and then use Send('reply @location') to reply to the person requesting the sense. However, the apostrophe in the @location variable causes the Send function to end after Entryway to Merchant and I'm left with s Quarter still trying to be sent to the MUD and MUSH doesn't know how to process that. Is there a way to get around this problem? It would be very helpful...
[Go to top] top

Posted by Worstje   Netherlands  (867 posts)  [Biography] bio
Date Reply #1 on Tue 11 Nov 2008 05:51 PM (UTC)  quote  ]
Message
That's the fundamental flaw with Send To Script. It is a literal paste into the code, meaning that it can make the syntax of the script incorrect and thus not work.

The best way to work around it (assuming you want to use a script for it) is to place a function in the main script file, and point to that. For example, make the script field say MindSense and put the following in your main script file (assuming Lua for the moment)

function MindSense(name, line, wildcs)
  Send('reply ' .. wildcs[1])
end


This assumes your trigger is an regular expression and looks like this (I play Aetolia so it might differ from Achaea's trigger):
^An image of (.+) appears in your mind\.$


There's an alternative way without scripting too, but in general, I find the scripting method to be simpler once you start adding stuff to it later, so this saves some effort in the long run (or it does for me). Either way, it should work. Let me know if you have any problems getting it to work.
[Go to top] top

Posted by Plyth   (5 posts)  [Biography] bio
Date Reply #2 on Tue 11 Nov 2008 06:32 PM (UTC)  quote  ]
Message
Okay thanks a lot. That is the same trigger line as the one in Achaea. I just need to learn a bit more about scripting in LUA and I'll figure it out. Thanks for your help!
[Go to top] top

Posted by Nick Gammon   Australia  (19,534 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 11 Nov 2008 06:40 PM (UTC)  quote  ]

Amended on Tue 11 Nov 2008 07:15 PM (UTC) by Nick Gammon

Message
Another approach is to not use the variable expansion the way you did. Instead of:


Send ('reply @location')


do:


Send ('reply ' .. GetVariable ('location'))


That way it doesn't matter what is in the variable 'location'.

- Nick Gammon

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

Posted by Plyth   (5 posts)  [Biography] bio
Date Reply #4 on Tue 11 Nov 2008 06:49 PM (UTC)  quote  ]
Message
Ah sweet, even better! I was just reading about concatenation and was wondering if that would work...

Thanks much!
[Go to top] top

Posted by Worstje   Netherlands  (867 posts)  [Biography] bio
Date Reply #5 on Tue 11 Nov 2008 07:31 PM (UTC)  quote  ]
Message
Yeah, but why go through a special location variable? The location variable would be set right from that same trigger. Just makes it messier and more errorprone in the long run.
[Go to top] top

Posted by Nick Gammon   Australia  (19,534 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Tue 11 Nov 2008 07:37 PM (UTC)  quote  ]
Message
I was responding to the specific query about the quotes. Maybe if we saw the whole trigger we could give a response to the whole thing. See http://mushclient.com/copying.

- Nick Gammon

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

Posted by Plyth   (5 posts)  [Biography] bio
Date Reply #7 on Tue 11 Nov 2008 07:51 PM (UTC)  quote  ]
Message
Okay, so that didn't actually work...still throws the same error message. Here are the triggers for it:

<triggers>
<trigger
enabled="y"
match="* tells you, "Mind sense *.""
send_to="12"
sequence="100"
>
<send>SetVariable('reporting','on')
Send('mind sense %2')</send>
</trigger>
</triggers>

<triggers>
<trigger
enabled="y"
match="An image of * appears*"
send_to="12"
sequence="100"
>
<send>local reporting
SetVariable('location','%1')
reporting = GetVariable('reporting')
if reporting == "on" then
Send('reply ' .. GetVariable('location'))
SetVariable('reporting','off')
end</send>
</trigger>
<trigger
enabled="y"
match="Whom do you wish to sense for?"
send_to="12"
sequence="100"
>
<send>local reporting
reporting = GetVariable('reporting')
if reporting == 'on' then
Send('reply Target not able to be sensed.')
SetVariable('reporting','off')
end</send>
</trigger>
</triggers>


and then I have two aliases to turn reporting on and off so that everytime I mind sense it doesn't reply with the person's location.

I tried doing it while standing at the location Golden Walk next to Philosopher's Plaza and got this error message:

[string "Trigger: "]:2: ')' expected near 's'

I hope this helps...
[Go to top] top

Posted by Nick Gammon   Australia  (19,534 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 11 Nov 2008 08:31 PM (UTC)  quote  ]

Amended on Tue 11 Nov 2008 08:35 PM (UTC) by Nick Gammon

Message
I am presuming this is the relevant part:


local reporting
SetVariable('location','%1')
reporting = GetVariable('reporting')
if reporting == "on" then
  Send('reply ' .. GetVariable('location'))
  SetVariable('reporting','off')
end


You have only partly solved the problem with:


Send('reply ' .. GetVariable('location'))


because earlier up you have:


SetVariable('location','%1')


This is also going to fail with the quotes.

One easy way around it is to use double quotes, rather than single quotes.

MUSHclient detects in "send to script" that quotes inside wildcards need to be escaped, however it only does it to double quotes, not single quotes.

Thus, change it to:


SetVariable('location',"%1")


That will work for any sort of quotes (single quotes won't matter, and double quotes will be escaped).

Another approach is to use Lua long strings, like this:


SetVariable('location',[=[%1]=])


They allow for any sort of quotes inside them, even if MUSHclient didn't escape them.

You might make it easier for yourself if you stuck to Lua variables - if these are simply temporary variables used in a single session (and not needed to be remembered for tomorrow), then using MUSHclient variables just makes it unwieldy.

So it might read:


location = "%1"

if reporting == "on" then
  Send('reply ' .. location)
  reporting = "off"
end


And if you don't use location anywhere else, make it simpler again:


if reporting == "on" then
  Send("reply %1")
  reporting = "off"
end


And better still, use booleans rather than strings for flags:


if reporting  then
  Send ("reply %1")
  reporting = false
end


- Nick Gammon

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

Posted by Plyth   (5 posts)  [Biography] bio
Date Reply #9 on Tue 11 Nov 2008 08:38 PM (UTC)  quote  ]
Message
Sweet, thank so much 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.


2,175 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]