mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Mar 2003
Posts: 9
im working on a script to check how many times a wildcard (specified in a trigger) appears in a rather large .txt file full of quotes.

eg: .qammount mirc
would return somthing like: "mirc" found in 13/417 quotes.

i thought i had it, but i'm stumped

what i'm trying to do, is make the script read every line by looping a string like this
Code:
 $read(C:\bot\bot_log_pub.txt, %currentline)
%currentline would be set to $calc($readn + 1) to check the next line

to stop the loop i would just use an if statement (if %currentline == %totalquotes) where %totalquotes would read "line 0" in the .txt file, line 0, if you didnt know, is a number that represents the total number of lines in the .txt file

basicly all i need to know, is how to scan only 1 line at a time, instead of the whole document.
thanks in advance - dak

ps: if you have a different way of completing my objective, feel free to post it, any help will be appriciated

Last edited by dak; 11/03/03 05:30 AM.

______________________________

123go
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Here is the code I came up with:
Code:
on *:TEXT:.qammount*:#:{
  var %l = 1,%r = 0
  while ( $read([color:green]test.txt[/color],w,* $+ $2- $+ *,%l) != $null ) {
    var %l = $readn + 1
    inc %r
  }
  msg # " $+ $2 $+ " found in %r $+ / $+ $read([color:green]test.txt[/color],0) quotes.
}


P.S. You could use $lines(test.txt) rather than $read(test.txt,0), it would save you having to fiddle around with the first number of the file everytime you added/removed a quote (if that's what you're doing, that is).

Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Mar 2003
Posts: 9
i appriciate your help, but...

that code, along with my other attempts, infinite loops and crashes the bot.

also, i never have to open the quote file to change anything because when you add a quote, it adds 1 to the line that lists how many lines there are, and it subtracts one if i delete a line.

Last edited by dak; 11/03/03 06:33 AM.

______________________________

123go
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
It wouldn't crash for me, you sure you don't have another one of your attempts still loaded? confused bah, oh well

Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Mar 2003
Posts: 9
well the wierd thing is, almost every time i try to use $null in a loop, it ends up doing that. Do i just suck with if-then-else statements or is somthing wrong with $null? crazy


______________________________

123go
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Another (faster) solution is /filtering the source file to a dummy window and checking $filtered to tell how many lines matched.
Code:

on *:TEXT:.qammount *:#:{
  window -h @@
  filter -fw file.txt @@ * $+ $2-*
  window -c @@
  msg # There were $filtered lines matching to ' $+ $2-'
}

Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Mar 2003
Posts: 9
i found somthing that didnt infinite loop

Code:
 on *:text:.qammount *:#:{ 
  set %line 1
  set %r 0  
  while ($read(C:\bot\bot_log_pub.txt, w, * $+ $2- $+ *, %line) != $null) {
    %line = $readn + 1
    inc %r
  }
  msg # " $+ $2- $+ " found in %r $+ / $+ $read(C:\bot\bot_log_pub.txt, 0) quotes.
}
 


______________________________

123go
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Use $lines(file) instead of $read(file,0)

Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Use the filtered one.. it's way faster, smaller and better.


* cold edits his posts 24/7

Link Copied to Clipboard