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
➜ Bug reports
➜ DeleteLines deletes 1 too many.
|
DeleteLines deletes 1 too many.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Smorly
(31 posts) Bio
|
| Date
| Wed 13 Feb 2013 08:09 PM (UTC) Amended on Wed 13 Feb 2013 08:11 PM (UTC) by Smorly
|
| Message
| I'm trying to deduplicate blank lines. When I match ^\s*$ with the following code (within a script, not send_to_script),
line_number = self.world.GetLinesInBufferCount
line_1 = self.world.GetLineInfo(line_number, 1).strip()
line_2 = self.world.GetLineInfo(line_number - 1, 1).strip()
line_3 = self.world.GetLineInfo(line_number - 2, 1).strip()
if line_1 == line_2 and line_1 in ['', '[OOC]', '[AFK]']:
self.debug('Deduplicated line %d!\nLine_3: %s\nLine_2: %s\nLine_1: %s' %
(line_number, line_3, line_2, line_1))
self.world.DeleteLines(1)
I get this debug output.
DEBUG 0: Deduplicated line 104!
Line_3: You are hungry.
Line_2:
Line_1:
This is all as expected. The output, however, looks like this:
You are hungry.
3:04 [INFO] Someone has left Antrippa.
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Wed 13 Feb 2013 09:53 PM (UTC) |
| Message
| Where does the debug output go?
Is this a trigger? Try doing it in "send to script". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Smorly
(31 posts) Bio
|
| Date
| Reply #2 on Wed 13 Feb 2013 11:32 PM (UTC) |
| Message
| The debug output goes to a different world.
I have a catchall trigger that enters all lines from the MUD onto a message bus. A handler on that bus detects the blank lines via regex and calls the aforementioned code.
Doing it in send to script does not delete any lines, as can be expected from the documentation:
Quote:
Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work.
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Wed 13 Feb 2013 11:39 PM (UTC) |
| Message
| You can do DeleteLines in send-to-script-after-omit. Example:
<triggers>
<trigger
enabled="y"
match="Exits:*"
send_to="14"
sequence="100"
>
<send>
DeleteLines (1)
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Smorly
(31 posts) Bio
|
| Date
| Reply #4 on Thu 14 Feb 2013 02:45 AM (UTC) |
| Message
| | Okay, I was running an old version. An upgrade fixed the problem. Sorry about the bug report. >< | | Top |
|
| Posted by
| Smorly
(31 posts) Bio
|
| Date
| Reply #5 on Thu 14 Feb 2013 04:28 PM (UTC) Amended on Thu 14 Feb 2013 04:46 PM (UTC) by Smorly
|
| Message
| Hmmmm.... I guess I didn't test thoroughly enough. Must have been tired last night. The problem still occurs exactly as described above using the same code.
To eliminate any other factor, I disabled my script and entered the following code into a trigger for ^\s*$ using send to script after omit:
line_number = world.GetLinesInBufferCount
line_1 = world.GetLineInfo(line_number, 1).strip()
line_2 = world.GetLineInfo(line_number - 1, 1).strip()
if line_1 == line_2 and line_1 in ['', '[OOC]', '[AFK]']:
world.DeleteLines(1)
I will note that this problem only occurs when there are two blank lines in a row. DeleteLine(1) correctly removes 1 line of text in other cases. I tested with OOC and AFK modes, and those deduplicate properly.
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Thu 14 Feb 2013 09:09 PM (UTC) |
| Message
| Looking at the source, I think the lines in bold are probably responsible:
void CMUSHclientDoc::DeleteLines(long Count)
{
POSITION pos;
/*
I can't delete lines when in send-to-script, please don't try to make me. ;)
The problem is that in ProcessPreviousLine we have established the start and end line
of the paragraph we are processing, if that is deleted by a trigger in the middle, all
hell breaks loose.
*/
if (m_bInSendToScript)
return; // can't do it
if (Count <= 0)
return; // nothing to do
// if we have the empty line at the end of the buffer, delete that too
if (m_pCurrentLine && m_pCurrentLine->len == 0)
Count++;
Now the reason for that code is that, once a line finishes, the client starts a new empty line (so there is always a "current" line).
Without that code, attempting to delete the last (non-blank) line only deleted the new, empty, line.
I suspect that in this case the line is not the "new empty" line, but the "old blank" one. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #7 on Thu 14 Feb 2013 09:11 PM (UTC) |
| Message
| Here's one workaround. :)
In the case of the de-duplication, put that empty line back.
Eg. in Lua:
<triggers>
<trigger
enabled="y"
match="^\s*$"
regexp="y"
send_to="14"
sequence="100"
>
<send>
line_number = GetLinesInBufferCount ()
line_1 = Trim (world.GetLineInfo(line_number, 1))
line_2 = Trim (GetLineInfo(line_number - 1, 1))
if line_1 == line_2 and line_1 == "" then
DeleteLines(1)
end -- if
Note "" -- put one blank line back
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Smorly
(31 posts) Bio
|
| Date
| Reply #8 on Thu 14 Feb 2013 09:24 PM (UTC) |
| Message
| Right, I'm using world.Note('') as a workaround right now :)
Okay, glad to know that it is indeed a bug. | | 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.
27,843 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top