mIRC Home    About    Download    Register    News    Help

Print Thread
#198322 26/04/08 03:34 AM
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Hi there,
The following script appears to be working correctly, but variable 'num' doesn't appear to show the correct line the script actually stopped on in the file. For some reason %num is a randum number each time, even though the line it stops at in the file is the same/correct one, its as though the script is too quick and doesn't get chance to update %num each time?

Code:
on 1:TEXT:!test1:#:{
  %var1 = textstring
  %num = 1
  :start
  %var2 = $read("file.txt), %num)
  %var3 = $gettok(%var2,1,58)
  if (%var1 == %var3) {
    goto end
  }
  else {
    %num = %num + 1
    goto start
  }
  :end
  msg $chan %num
}


Any help please?

Thanks


Ninko

Last edited by Ninko; 26/04/08 03:46 AM.
Ninko #198323 26/04/08 03:46 AM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
There is a little problem in your code :
Quote:
%var2 = $read("file.txt), %num)
Here, there is a problem with ), and you have only one ", should be $read("file.txt",%num)
But you should use while instead of goto and local variable :
Code:
on *:TEXT:!test1:#:{
  var %s = textstring ,%n = $lines("file.txt")
  while (%n) {
  var %v = $read("file.txt",%n) ,%r = $iif(%v == $gettok(%v,1,58),0,1)
  if (%r) dec %n
  else { msg $chan %n | break } 
 }
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #198324 26/04/08 03:54 AM
Joined: Jun 2004
Posts: 139
N
Ninko Offline OP
Vogon poet
OP Offline
Vogon poet
N
Joined: Jun 2004
Posts: 139
Thanks for the reply. One question though, why are while loops better then goto loops?

Thanks


Ninko

Ninko #198325 26/04/08 04:37 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
they're easier to look at, manage and maintain, and easier to figure out what went wrong when something does.

For instance, upon first glance I had no clue your code even looped until it was rewritten with while

With while, the loop was obvious.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Ninko #198335 26/04/08 11:40 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Apart from the valid points mentioned in this thread, you don't really need a loop here: you can use $read()'s w switch, to have mirc search the file itself for lines matching textstring:* (type /help $read for more)
Code:
on 1:TEXT:!test1:#:{
  noop $read(file.txt,w,textstring:*)
  msg # $readn
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard