Using matched strings without parsing them

Posted by Thenate on Tue 17 Sep 2019 09:35 PM — 3 posts, 12,850 views.

#0
(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
'say %1'
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?
Australia Forum Administrator #1
I've read your question a couple of times and am not sure what you mean. Can you please show this trigger?

Template:copying
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.
#2
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, &quot;*&quot;"
   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.