|
Joined: Apr 2006
Posts: 3
Self-satisified door
|
OP
Self-satisified door
Joined: Apr 2006
Posts: 3 |
Hi everyone, I made a script for a game I play that reads through a file (which is aroung 5000 lines) and while it is processing, it complety freeze my mirc for this period of time (which can be about 4-5 sec). I was wondering if there was a command (such as System.Windows.Forms.Application.DoEvents() in vb.net) for mIRC so it doesn't freeze  The script is (note that I'm not a mirc expert, I've made this from reading tuto on other website, but it works perfectly):
on *:TEXT:!profile*:#:{
msg $chan Processing, please wait...
set %found 0
set %name $$2
set %name $chr(91) $+ %name $+ $chr(93)
set %textfile CensusPlus.txt
set %a 1
set %b $lines(%textfile)
while %a <= %b {
set %currentline $read(%textfile,nt,%a)
if (%name isIn %currentline) {
set %found 1
set %info $read(%textfile,nt,%a)
msg $chan %info
halt
}
inc %a
}
if %found == 0 {
msg $chan Sorry, I have no infos on %name .
}
}
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
without making too much of change (like using /filter -tt censusplus.txt temp.txt and then reading/playing that to $chan) I edited your
on *:TEXT:!profile *:#:{
msg $chan Processing, please wait...
set %name $+($chr(91),$$2,$chr(93))
var %a = 1
var %b = $lines(CensusPlus.txt)
while (%a <= %b) {
if (%name isIn $read(CensusPlus.txt,nt,%a) {
var %info = %info Line # $+ %a %name $read(CensusPlus.txt,nt,%a)
msg $chan %info
inc %a %b
}
inc %a
}
if (%info == $null) {
msg $chan Sorry, I have no infos on %name $+ .
}
} uses var %variable so they are local (and are destroyed when the script exits) so you dont have unwanted saved data in ram (it all adds up you know) eliminated the %filename, but the advantage might be to use %filename so that if the txt file is changed later you only need to change the one line (still could be a var %name =) look over the /filter in help (/help /filter) also see the local variables section (/help /var )
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
improved
on *:TEXT:!profile *:#:{
msg $chan Processing, please wait...
var %name = $+($chr(91),$$2,$chr(93))
filter -ffc CensusPlus.txt temp.txt $+(*,$$2,*)
if ($read(temp.txt,1) != $null) {
msg $chan Info For %name
.play $chan temp.txt
}
elseif ($read(temp.txt,1) == $null) {
msg $chan Sorry, I have no infos on %name $+ .
}
} try that out after reading up on the /filter in help
|
|
|
|
Joined: Apr 2006
Posts: 3
Self-satisified door
|
OP
Self-satisified door
Joined: Apr 2006
Posts: 3 |
Yay! It works like a charm now  Even tho I don't understand the filter thing at 100% I somewhat understand the base  Thanks for the help!
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
Yay! It works like a charm now  Even tho I don't understand the filter thing at 100% I somewhat understand the base  Thanks for the help! in this case the filter -ffc is filter from file1 to file2, clearing the "file2" file before doing the filter task so there is no erronious data in there after the file names is the data to look for Filter From File1 to File2 *data to look for* filter -ffc censusplus.txt temp.txt *nickname* /help $+ Other Identifiers
$+(n1,...,nN) Combines all of the specified parameters, the same as using $+ in between each item.the filter uses the * wildcard before and after to find it in the string like "isin" does
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Since his code stops after locating the first occurance, I would assume there should only be 1 occurance, or at least only one is displayed, so filtering might not be the best idea. on *:TEXT:!profile *:#:{
if ($read(CensusPlus.txt,ntw,$+(*,$$2,*))) {
msg $chan Info for $2 is $v1
else {
msg $chan Sorry, I have no info for $2 $+ .
}
}
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
Because he mentioned that mIRC stalled while the script processed I suggested the filter, which in general seems to not stall like the $read does (he mentions 5000+ lines int eh census file)
The read will work, the filter will work as well, his original code worked but he used set global vars instead of the local vars. I only tested with a file having three lines in it so it was not likely i would see any differerence in performance.
you used $v1 which is of course nice and clean ( I really need to catch up on some things)
otherwise, tell me again why $read is better than filter in this case
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
tell me again why $read is better than filter in this case The $read i used searches the file for the first instance only then stops having to read and compare lines of the file, an average of 2500 lines read per search, with no file writes. Filter well read ALL the file everytime looking for all matches, an average of 5000 lines read per search, with one or more file writes. While your routine had advantages of being able to display all matching lines, it can be assumed since his orginal code halted after the first match that there should only be one line that matches, or only the first matching line was required.
|
|
|
|
|