mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
This script returns the line numbers of each match:

Code:
ON *:TEXT:*script*:?: {
 var %file = ini\userips.ini
 var %sect = userips
 var %x, %m = 0, %i = 0, %ii = $ini(%file,%sect,0)
  while (%i < %ii) {
    inc %i
    %x = $ini(%file,%sect,%i)
    if ($2 isin $readini(%file,%sect,%x)) {
      .msg $nick %i
    }
  }
}


Instead of returning the line numbers, how can I return the total number of matches found?

Last edited by Joe_Dean; 25/10/08 03:59 AM.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Set a variable to 0 before the while-loop, then /inc it everytime you find a match.

-genius_at_work

Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Yeah, that's what I figured, but for some reason it's still returning the line number. smirk

Joined: May 2008
Posts: 127
J
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
If you look at my script though, it says: %i = 0 then it /inc's right after the loop

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
On the contrary, your increment of the %i variable occurs at the beginning of the loop, not the end.

Genius' suggestion requires another variable that is initialized before the loop (as your current variables are being initialized already), then incremented when there is a match. You don't have an increment that occurs when the if statement is true.

Code:
ON *:TEXT:*script*:?: {
 var %file = ini\userips.ini, %sect = userips, %ii = $ini(%file,%sect,0), %x, %m, %i
  while (%i < %ii) {
    inc %i
    %x = $ini(%file,%sect,%i)
    if ($2 isin $readini(%file,%sect,%x)) {
      inc %m
      .msg $nick $2 has been matched %m times
    }
  }
}
Code edited for the variable and to have a clearer message displayed.


Link Copied to Clipboard