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
➜ Apostrophes in Variables sent to script
Apostrophes in Variables sent to script
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Plyth
(5 posts) Bio
|
Date
| Tue 11 Nov 2008 04:47 PM (UTC) |
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... | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #1 on Tue 11 Nov 2008 05:51 PM (UTC) |
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. | Top |
|
Posted by
| Plyth
(5 posts) Bio
|
Date
| Reply #2 on Tue 11 Nov 2008 06:32 PM (UTC) |
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! | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 11 Nov 2008 06:40 PM (UTC) 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:
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 | Top |
|
Posted by
| Plyth
(5 posts) Bio
|
Date
| Reply #4 on Tue 11 Nov 2008 06:49 PM (UTC) |
Message
| Ah sweet, even better! I was just reading about concatenation and was wondering if that would work...
Thanks much! | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #5 on Tue 11 Nov 2008 07:31 PM (UTC) |
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. | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #6 on Tue 11 Nov 2008 07:37 PM (UTC) |
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 | Top |
|
Posted by
| Plyth
(5 posts) Bio
|
Date
| Reply #7 on Tue 11 Nov 2008 07:51 PM (UTC) |
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...
| Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #8 on Tue 11 Nov 2008 08:31 PM (UTC) 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 | Top |
|
Posted by
| Plyth
(5 posts) Bio
|
Date
| Reply #9 on Tue 11 Nov 2008 08:38 PM (UTC) |
Message
| Sweet, thank so much 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.
22,260 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top