mIRC Homepage
Posted By: FroggieDaFrog buffer change detection - 17/06/11 05:40 AM
While coding[isn't that where ppl realize they don't have what they need?] I realized there wasn't a decent way to test if the buffer of a window has changed, be it due to user's /echoing, an error in a script, etc

So I suggest one of two ways:
Code:
on *:BUFFERCHANGE:window:{ 
  $target == window whom's buffer has changed
}
and/or
Code:
/window -Z name
  Resets $window().CBuffer to $false

$Window().CBuffer
   returns $True/False if the buffer of the specified window has changed since the last /window -Z
Posted By: Wims Re: buffer change detection - 17/06/11 10:31 AM
See https://forums.mirc.com/ubbthreads.php/ubb/showflat/Number/228993/page/2#Post228993
Posted By: Thrull Re: buffer change detection - 18/06/11 06:23 AM
You just use $line(Window,0) to get the number of lines. Set that to a variable, then set a timer to check and see if that number has changed.

While I admit it might be handy to have, the other thread mentioned shows some pretty good reasons not to do such a thing.

Edit: Actually, the above won't work if you're at the buffer limit. You could still set the last line to a variable (with a timestamp if need be) and then set up a timer that compares it to the last line in the buffer. Slightly more complex, but it gets the job done.
Posted By: FroggieDaFrog Re: buffer change detection - 18/06/11 11:24 AM
For the most part something like that works, but what happens if a channell is getting flooded, a timer goes haywire, the user is //echo testing something, all with a full buffer? There's really no way to detect that.

I'm not asking for a unique identifier for each line[though that would be GRAND!], just a WAY to tell if the buffer changed. Seriously, there are so many ways to change the buffer [not even including when data is received from an IRC server] that to be able to track as much as possible of the buffer changing commands/events would take quite the bit of coding. And still echoed errors and such still wouldn't be able to be caught....
Posted By: Riamus2 Re: buffer change detection - 18/06/11 02:18 PM
@Thrull: If you read that thread a bit more, you'll see reasons why your examples aren't going to work well. You already edited to point out why total lines isn't going to work. You also can't check the last lines because it's very possible to have two lines (or more) be the same. There are some examples of how to get accuracy up to around 99.9% or so (checking top, bottom, and at least one middle line... more increases accuracy) and for most things, that really is enough.

@FroggieDaFrog: It doesn't take that much code to check multiple lines for changes and it's very accurate. The chances of it not being correct are extremely low. You can even avoid such a line check and just save the buffer and check it's hash. Of course, that's more CPU intensive and depending how often your check it, it may not be worth it. But it requires very little code to do.

In any case, this should be very easy to add and would be worth adding. mIRC already knows when there are changes, so providing an event for them shouldn't be hard. It probably needs to be limited in scope, though... as mentioned, you don't want it to override on text or anything else.
Posted By: FroggieDaFrog Re: buffer change detection - 19/06/11 08:36 AM
I thought about it some more, and the problem isn't detecting if the buffer changes, it's really detecting when a line is deleted from the front of the buffer to make room for a line at the end, so something like: on *:BufferDelete:window:{ } would suffice.
Posted By: Riamus2 Re: buffer change detection - 19/06/11 12:47 PM
That won't work if you're not at full buffer, though. Unless you want to count lines and do that, which seems like extra work for no reason.
Posted By: Thrull Re: buffer change detection - 20/06/11 07:12 AM
Quote:
@Thrull: If you read that thread a bit more, you'll see reasons why your examples aren't going to work well. You already edited to point out why total lines isn't going to work. You also can't check the last lines because it's very possible to have two lines (or more) be the same. There are some examples of how to get accuracy up to around 99.9% or so (checking top, bottom, and at least one middle line... more increases accuracy) and for most things, that really is enough.


On the average channel, doing a bit of mid section checking should get you up far beyond 99.9%. But point taken, it won't be 100% and that can matter.
© mIRC Discussion Forums