DeleteLines()

Posted by Indoum on Sat 29 Jul 2006 05:25 PM — 6 posts, 23,685 views.

Sweden #0
I was anxious to remake my entire visual-system with the DeleteLines() function. I made a simple trigger and tried it out. But MUSHclient crashed. Restarted MC and tried again, then it worked. After that I've tried maybe five times, everytime crashing the client without any discernable pattern.

The trigger I'm using is this:
<trigger>
    <trigger enabled="y" keep_evaluating="y" match="^Using your daegger, you open a vein in your wrist\, and let the blood drip to \noutline a pentagram\, floating waist-high\.$" regexp="y" multi_line="y" lines_to_match="2" send_to="12">
        <send>DeleteLines(2)
Note("Pentagram")</send>
    </trigger>
</triggers>
Australia Forum Administrator #1
Hmmm, I see the problem here, this reminds me of why I wasn't in a big hurry to allow deleting in the first place.

During trigger processing MUSHclient has identified the last paragraph in the output buffer (set of lines terminated by a newline), and is applying trigger processing on that paragraph, followed by optional logging, etc.

However by doing DeleteLines in a send-to-script trigger you have yanked those lines away from it in mid-stream. Internally (in trigger/logging processing) it doesn't realize they are not there and crashes with bad pointers.

There would be a similar problem if you did DeleteLines in a trigger that went on to omit from output. It would try to omit the lines twice.

I think the solution in your case will be to call a script function (not send-to-script).

I am going to have to place a restriction on DeleteLines that it cannot be called from send-to-script, there are just too many problems if you do that.
Australia Forum Administrator #2
Version 3.77 will now not allow you to call DeleteLines from send-to-script or a plugin callback.

I have amended the documentation on this site to mention this problem.
Sweden #3
Ahh, didn't realize that's your intended use for it.

Now, is there any way for my script functions to detect the number of lines that the trigger fired on? Search for \n in the line-parameter? I could ofcourse define that number, along with the text to replace the output, in the send-to script. Just wondering if there's any other way.
Australia Forum Administrator #4
No, searching for the \n will not work. See:

http://www.gammon.com.au/scripts/doc.php?function=GetLineInfo

You need to look for selector 3 (true if newline), however what you really want is to find the 2nd last line with a newline, + 1.

eg.


100: You feel rested.  <--- newline
101: Lorem ipsum dolor sit amet, consectetuer adipiscing elit, 
102: sed diam nonummy nibh euismod tincidunt ut laoreet dolore 
103: magna aliquam erat volutpat. Ut wisi enim ad minim veniam, 
104: quis nostrud exerci tation ullamcorper suscipit lobortis nisl 
105: ut aliquip ex ea commodo consequat.   <--- newline


Now line 105 has a newline, however you would expect that. Line 100 is the last line from a previous batch, so line 101 is the start of the current paragraph.
Australia Forum Administrator #5
However my remarks really only apply to a single-line trigger. For a multi-line one you might need to reapply the regexp from the multi-line trigger, on lines, working backwards from the end, until you find a match, to reliably find which line started the batch.