|
|
Joined: Jun 2004
Posts: 139
Vogon poet
|
OP
Vogon poet
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?
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.
|
|
|
|
Joined: Jul 2006
Posts: 4,222
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,222 |
There is a little problem in your code : %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 : 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
|
|
|
|
Joined: Jun 2004
Posts: 139
Vogon poet
|
OP
Vogon poet
Joined: Jun 2004
Posts: 139 |
Thanks for the reply. One question though, why are while loops better then goto loops?
Thanks
Ninko
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
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"
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
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) on 1:TEXT:!test1:#:{
noop $read(file.txt,w,textstring:*)
msg # $readn
}
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
|
|