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
➜ Using matched strings without parsing them
|
Using matched strings without parsing them
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Thenate
(2 posts) Bio
|
| Date
| Tue 17 Sep 2019 09:35 PM (UTC) |
| Message
| (Using default, so language is Lua)
This is such an elementary thing, I'm embarrassed to post it, but I've been looking through the documentation to no avail.
I have a trigger that pulls in a substring which I'm using to generate a hyperlink. I take that (%1) and add text to it to make the command which works. I'd also like to take the entire string and send it as the new string text. Nothing all that wacky.
My issue is:
The %1 expands before parsing so I only need to say to get the output I want, but this also means that the match can't include single quotes. (Also allows for code injection, come to think, but that's beside the point) When the MUD mixes things like that, the script gags and dies.
How do I pull in a matched string or substring to a variable that I can supply a function without it seeing it as literal text to parse? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Wed 18 Sep 2019 05:37 AM (UTC) |
| Message
| I've read your question a couple of times and am not sure what you mean. Can you please show this trigger?
 |
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
The whole string is %0 if you are using send-to-script.
The problem with quotes goes away if you use a script file rather than sending to script in the Send box. Use the Scripting configuration to make an empty script file (and choose that as the script file). Then you can put your trigger in it like this:
function mytrigger (name, line, wildcards, styles)
Send ("say ", wildcards [1])
end -- function
Now put "mytrigger" in the "Script" box of your trigger and just leave the Send part empty and have it send to the world.
Now the "line" variable is the whole matching line, so you can do something with that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Thenate
(2 posts) Bio
|
| Date
| Reply #2 on Wed 18 Sep 2019 05:48 AM (UTC) Amended on Wed 18 Sep 2019 06:34 AM (UTC) by Thenate
|
| Message
| I'm going to try that. I think you answered my question.
The reason I didn't post the trigger it is that I figured it would distract from said question, which was more fundamental than that. Still, since you asked, the best version I'm working with:
<triggers>
<trigger
enabled="y"
match="You think to say, "*""
omit_from_output="y"
send_to="14"
sequence="100"
>
<send>Hyperlink ("say %1", 'You think to say, "'.."%1"..'"', "Respond with this", "yellow", "black", 0)</send>
</trigger>
</triggers>
It isn't stable or pretty, though, which is why I asked the question.
If I'm understanding things, I want a function something like :
function intercourse_response (name, line, wildcards, styles)
Note (line)
Send ("say ", wildcards [1])
end -- function
Having some issues getting it set up, if so, but this seems like progress.
Edit: Nope, more like this:
function intercourse_response (name, line, wildcards, styles)
reply="say "..wildcards[1]
Hyperlink(reply, line, reply, "yellow", "black", 0);
end -- function
and, as you say, have this added to the world settings as a script
Set up a trigger with Script after omit
call intercourse_response as the script
and it works beautifully. Now I just need to work some hoodoo cleaning up my regular expressions calling it.
Thanks, man. That helped a lot. I *knew* it was a pretty simple problem if I could just see what I was missing. | | 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.
11,997 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top