DeleteLines() doesn't always actually delete the lines

Posted by tobiassjosten on Mon 16 Mar 2009 07:41 PM — 11 posts, 31,137 views.

Sweden #0
I recently returned to using MUSHclient (version 4.37) and am now fiddling around to see how I can refit my system to take full advantage of all the goodies you stuffed it full of these last years. One problem I am having is with my visuals and text substitution. The test code I have set up is as follows.

<script><![CDATA[

function substitute(name, line, wildcards, styles)
	_, count = wildcards[0]:gsub('\n', '')
	DeleteLines(count + 1)
	if message then
		Note(message)
		message = nil
	end
end

]]></script>

<triggers>
  <trigger
   enabled="y"
   lines_to_match="2"
   keep_evaluating="y"
   match="^You are ranked (\d+)st in Imperian\.\nYou are ranked (\d+)st in Questing\.$"
   multi_line="y"
   regexp="y"
   script="substitute"
   send_to="12"
  >
  <send>message = 'Overall and Questing rank replaced'</send>
  </trigger>
</triggers>


It works like a charm! Except for the fact that every now and then, the DeleteLines() function leaves an empty line. It most often happens with the single line trigger (about seven out of ten times) but also sometimes with the multiline one (about two out of ten times).

Am I doing something wrong here or is there a bug with DeleteLines?
Amended on Mon 16 Mar 2009 08:10 PM by Nick Gammon
Australia Forum Administrator #1
Well in that example it would appear you always need to delete 2 lines. Are there other examples with variable lines to delete?

I would try changing the trailing $ to \z (end of subject).

Also try changing the ^ to \A (start of subject).

Australia Forum Administrator #2
Quote:

It most often happens with the single line trigger (about seven out of ten times) ...


Can you paste the single-line trigger then?
Sweden #3
I added it above but I suspect you might accidently edited it away. :) It follows below.

<trigger
 enabled="y"
 keep_evaluating="y"
 match="^You are the \d+th ranked arena combatant with \d+ wins\.$"
 regexp="y"
 send_to="12"
 script="substitute"
>

<send></send>

</trigger>


It has the same callback, which counts the number of newlines (N) in the matching text and deletes lines accordingly (N+1 amount).

I tried changing the patterns to use \z and \A instead but it still leaves occasional blank lines.
Australia Forum Administrator #4
Oops, sorry. I fixed the formatting by pasting into MUSHclient and copying back but didn't notice the 2nd one.

I can reproduce your problem, not sure why. If you remove the message the extra line goes away. The blank line is marked as a note rather than MUD input.

What seemed to work for me was change Note to Tell. Then you see the message, and the blank line disappears. This is a bit of a kludge, but I think somehow after the omit there is a problem with transitioning back from a Note (which you put there) and the next line of output.
Sweden #5
Thanks for looking into it so rapidly!

I tried removing the message bit all together, like how it's not used in the single line trigger. But that still leaves the blank line for me. So in my case, the Note/Tell doesn't affect whether an empty line is left after the omit.

Any other suggestion as to what could be wrong? Do you need any other information from me to debug it perhaps?

I am running MUSHclient under Wine with pretty much the default configuration, except for checking "convert IAC/GA to newline" and "match on empty lines". These two are my only triggers and I have placed them, along with the script, inside a plugin.
Sweden #6
Can anyone else please give some suggestion(s) as to how I could proceed with this? Or is it perhaps a bug in MUSHclient that I will just have to try and live with for now?
Australia Forum Administrator #7
Since most of your problems (seven out of ten times) occur with a single-line trigger, simply make that trigger omit from output.

However upon investigating this problem I see things are worse than I thought.

For example, if I make a trigger to match on "blah" and use your trigger function to omit one line, and then send this:



aaaa
blah
blah
bbbb



What I see in the output window is:


aaaa
b
bbb


So there seems to be some serious issues with DeleteLines, and I will investigate that.
Australia Forum Administrator #8
There appeared to be a subtle bug in DeleteLines. After deleting the line, it added a new blank one (as there has to be a line always for the next lot of input). However after processing the triggers, at the end of a line, it also adds a new line. It appeared that the bug hinged upon whether or not the memory allocator happened to give the same memory address to the new line, as the deleted one had. I think it is fixed now in version 4.41, however you may want to report on whether it works better now.
Sweden #9
You, my good sir, kick some serious ass!

I take it you haven't released 4.41 yet? Or maybe I'm just looking at the wrong place.
Australia Forum Administrator #10
Correct, not released yet.