mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2009
Posts: 17
A
AD1C Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2009
Posts: 17
Ever since installing Windows 7, mIRC has been hanging for seconds at a time when using the attached script (assuming I can figure out how to attach it).

Here's how to cause the problem. Start mIRC and load the cht.mrc script. You will need to connect to this server:

W6RK
irc.w6rk.com
port: 6667

Then join the #ch channel

Once the channel window comes up (* Now talking in #ch), right-click and choose "CHT CONFIG". It will take several seconds for the config to come up. It should be instant, and it was instant under Windows XP. Also, during the course of using this channel, the program will randomly hang for seconds, then return control.

Maybe the script is the problem. I didn't write it. If there's something that needs to change, let me know!

LINK to download script: http://www.ad1c.us/cht.mrc

Last edited by AD1C; 22/09/11 01:24 AM.

Jim Reisert
http://www.ad1c.us/
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
the bottleneck appears to be those 3 'loadspecialneeds' aliases called at the end of /config. i don't have mIRC on this machine to confirm this, but they each use the notorious '$read() loop' which is famously slow due to the fact that mIRC needs to repeatedly count lines from the beginning of the file to find the Nth line for each call to $read(). if your specialneeds*.txt files are large, the hanging is quite understandable.

change these lines:

Code:
alias loadspecialneeds {
var %q = $lines(specialneeds.txt)
if %q = 0 { return }
unset %num
:nextline
inc %num
did -a config 302 $read(specialneeds.txt,%num)
if %num < %q goto nextline
return
}
alias loadspecialneeds2 {
var %q = $lines(specialneeds2.txt)
if %q = 0 { return }
unset %num
:nextline
inc %num
did -a config 402 $read(specialneeds2.txt,%num)
if %num < %q goto nextline
return
}
alias loadspecialneedscw {
var %q = $lines(specialneedscw.txt)
if %q = 0 { return }
unset %num
:nextline
inc %num
did -a config 502 $read(specialneedscw.txt,%num)
if %num < %q goto nextline
return
}


to this:

Code:
alias loadspecialneeds loadbuf -o config 302 specialneeds.txt
alias loadspecialneeds loadbuf -o config 402 specialneeds2.txt
alias loadspecialneedscw loadbuf -o config 502 specialneedscw.txt


i have to run off now, but i'll take a look at the rest of it later


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Please post script problems in the correct forum. This is unlikely to be a bug in mIRC and posting it in the bugs forum just causes confusion.

Also, scripts that are not updated will eventually fail either due to changes in newer versions of mIRC or, in some cases, newer versions of your OS. If you are not able to update the scripts you use yourself, then it's a good idea to use only scripts that are updated fairly regularly or at least have a strong following so that someone else will update it if needed. Otherwise, you are likely to run into problems like this. And with large scripts like that, you won't always find someone willing to troubleshoot it for you if they aren't also using it. Be grateful that jaytea is willing to do so.

And just a quick glance at that script tells me that it wasn't written all that well and could probably be cut down in size by at least 50% and made much more efficient. jaytea's fix above gives you an idea of how inefficient this script is. You might want to contact others who use this script and see if any of them know how to script. Maybe one of them will consider writing a new script to replace this one.


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2009
Posts: 17
A
AD1C Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2009
Posts: 17
Thanks, jaytea. Your suggested changes made a *huge* performance improvement.

How should I go about moving this topic to the Scripts forum?


Jim Reisert
http://www.ad1c.us/
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Once posted, only moderators can move topics. Don't worry about it. I just mentioned it for future reference. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2009
Posts: 17
A
AD1C Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2009
Posts: 17
The checkneeds, checkneeds2 and checkneedscw loops also seem to be susceptible to the read() loop issues. Can you suggest a better way to do this, and I'll re-write all three? I'm a programmer (C/Verilog/Perl/etc.) but not all that familiar with the mIRC scripting language.


Jim Reisert
http://www.ad1c.us/
Joined: Aug 2006
Posts: 183
T
Vogon poet
Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
Using /filter or $fopen and $fread are generally better than looping $read statements.

/filter, if set up correctly, should only need to open the file once. $fopen and $fread will open the file until you close it, and would generally be easier to use in a script.


Yar
Joined: Nov 2009
Posts: 17
A
AD1C Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2009
Posts: 17
Here's the new code I wrote. I based it on the example in:

http://script.quakenet.org/wiki/Why_and_how_to_use_File_Handlers#Reading_from_the_Stream

I think this will work OK, no? I also assume that %readline will be able to be used by the calling alias, right?

Please let me know if/what I messed up! I wasn't sure how to pass the filename into the checkspotforcounty alias, and how to check its return value in an if () {} statement.


alias checkspotforcounty {

set %filename $$1

if (!$isfile(%filename)) { return $false }
if ($fopen(specialneeds)) { .fclose specialneeds }
.fopen specialneeds %filename

while (!$fopen(specialneeds).eof) {

set %readline $fread(specialneeds)

set %county $left(%readline,-4)
set %state $right(%readline,4)
if ( ( %county isin %spotline ) &&
( %state isin %spotline ) ) {
unset %state %county %filename
.fclose specialneeds
return $true
}
}

unset %state %county %filename
.fclose specialneeds
return $false
}


alias checkneeds {
if $readini(cht.ini, options, needdisable) = 1 { return }

# I need %filename later which is why it's set here
set %filename specialneeds.txt

if ( (checkspotforcounty %filename) == $false ) {
unset %filename %readline
return
}

... etc.


Jim Reisert
http://www.ad1c.us/
Joined: Nov 2009
Posts: 17
A
AD1C Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2009
Posts: 17
It appears I should have written the check like this:

if ( $checkspotforcounty(%filename) == $false ) {
...
}

At least mIRC isn't throwing up syntax errors on this one.

- Jim


Jim Reisert
http://www.ad1c.us/

Link Copied to Clipboard