Matching two lines of text

Posted by Blixel on Mon 04 Sep 2017 04:02 PM — 8 posts, 33,730 views.

#0
I'm trying to set up a regular expression that will suppress output to the screen of the following text:
>say openthechest
***


I'm able to do this if I set up 2 triggers. The first one looks for:
^\>?say openthechest$

And the second one looks for:
^\>?[*][*][*]$


I should be able to do this with 1 trigger, but I can't seem to figure out what's missing. I've tried:
^\>?say openthechest$\n[*][*][*]$

and
^\>?say openthechest\n[*][*][*]$

and
^\>?say openthechest$\r\n[*][*][*]$

and
^\>?say openthechest\r\n[*][*][*]


...but I can't seem to capture both lines in one trigger.

https://i.imgur.com/Q8vqU1r.jpg
Australia Forum Administrator #1
There are multi-line trigger, but they don't let you omit the lines from output.

You could use a multi-line trigger, and then the DeleteLines function to delete two lines.

Template:function=DeleteLines
DeleteLines

The documentation for the DeleteLines script function is available online. It is also in the MUSHclient help file.

#2
Nick Gammon said:

There are multi-line trigger, but they don't let you omit the lines from output.

You could use a multi-line trigger, and then the DeleteLines function to delete two lines.


Ok, I got the multi-line trigger working finally. I verified it was working by just putting a Note() out to the screen. But I'm not sure how to get DeleteLines() function to work. The link you posted says it can't be used in a Trigger. So placing DeleteLines(2) in the trigger won't delete the previous 2 lines. So how do you use it then?
Australia Forum Administrator #3
See the help for that function:

Quote:

Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).

If you want to call DeleteLines from a trigger you must call a function in your script file (or plugin script), not directly from send-to-script.


In other words, make a script file, put a function into it, and put the name of the function in the trigger as the script to be called.
#4
Nick Gammon said:

See the help for that function:

Quote:

Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).

If you want to call DeleteLines from a trigger you must call a function in your script file (or plugin script), not directly from send-to-script.


In other words, make a script file, put a function into it, and put the name of the function in the trigger as the script to be called.


First, I apologize for my ignorance as I realize this seems brain-numbingly simple to you.

I created a script called deleteLines.lua which now contains the following:
function deleteTwoLines()
  DeleteLines(2)
end


I assume I have to go to World Properties -> Scripting -> Scripts and include that script as an External Script File.

Then, I've gone to my Multi-line trigger and added the line deleteTwoLines() so that it will call the function I created.

I know the trigger is being, well, triggered, because I have a Note("Trigger is working") which I can see on the output. However, the 2 lines that I am trying to omit are not being omitted.

So there is still some part of this brain-numbingly simple problem that I am too ignorant to sort out. Apologies once again for my intellectual inferiority.

EDIT: I'm wondering if this would be better http://www.gammon.com.au/forum/?id=10453 ... using CallPlugin instead of an external script? (Since there can apparently only be 1 external script, but you can have as many plugins as you want as far as I can tell.)

I'm trying to make this plugin:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, September 05, 2017, 7:37 PM -->
<!-- MuClient version 5.05 -->

<!-- Plugin "deleteTwoLines" generated by Plugin Wizard -->

<muclient>
<plugin
   name="deleteTwoLines"
   author="muclient"
   id="6eb408421deaede0c6a61a36"
   language="Lua"
   purpose="Deletes the last 2 lines from the output display"
   date_written="2017-09-05 19:36:11"
   requires="5.00"
   version="1.0"
   >

</plugin>

<!--  Script  -->

<script>
<![CDATA[

function OnPluginPacketReceived (s)
end -- OnPluginPacketReceived

]]>

function deleteTwoLines ()
  DeleteLines(2)
end -- deleteTwoLines

</script>

<!--  Get our standard constants -->

<include name="constants.lua"/>

</muclient>


And then I'm having my trigger call it with:
CallPlugin ("6eb408421deaede0c6a61a36", "deleteTwoLines")


It's not working ... but it seems like this would be the superior option if I can get it working.
Amended on Tue 05 Sep 2017 11:04 PM by Blixel
Australia Forum Administrator #5
It works:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^foo\nbar$"
   multi_line="y"
   regexp="y"
   script="deleteTwoLines"
   sequence="100"
  >
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


You can't call deleteTwoLines inside send-to-script, you have to put the function name in the script box. Paste that trigger and you'll see what I mean.

I doubt if the plugin method will work because you will have to call that from send-to-script which hits the issue of not using send-to-script.
#6
Nick Gammon said:

It works:

You can't call deleteTwoLines inside send-to-script, you have to put the function name in the script box. Paste that trigger and you'll see what I mean.


Ok this does work, though it seems to introduce a new issue. I can live with it though if I have to. But the way I've been using this is to call EnableTrigger() just before and after the trigger to turn it on and then back off. That way it only gets activated during the few milliseconds that is required for muclient to hide the unwanted text. But now that I'm sending to World instead of Script, I don't have a way to shut that trigger back off after it's called. Right?

In this case, that is probably ok. The text that activates the trigger isn't something that would normally appear. But for the sake of completeness, I do like the idea of only having these kinds of triggers activated at the very moment they are being used, and then instantly shut back off.

Nick Gammon said:
I doubt if the plugin method will work because you will have to call that from send-to-script which hits the issue of not using send-to-script.


I see.
Australia Forum Administrator #7
Quote:

I don't have a way to shut that trigger back off after it's called.


You can send to script, and turn the trigger off, sure. Just don't do the DeleteLines that way.




Of course, the script function you call could do that anyway. Why not?