mIRC Homepage
Posted By: VinceNad Cycling - 13/05/03 11:16 PM
Hi, can anyone help me? What I'm trying to do is make the script cycle through a list of things to say rather than just a random one via { $read file.txt } for my little known fact file.

(trigger code in separate script file)
on *:TEXT:!LKF*:*:{ /msg # Litte Known Fact : $read LKF.txt }

(LKF.txt)
Boogers are NOT an excellent source of protien.
Numchucks are NOT an actual oriental weapon.

^^This is what I have, I want it to cycle rather than read a random line. you know, it reads line one then line two, then line three. I don't know how to use variables yet I'm not that advanced. So could someone please give me a hand? Thanks ahead of time.
Posted By: Nimue Re: Cycling - 13/05/03 11:34 PM
Code:
on *:TEXT:!LKF*:#:{
  inc %read.lkf
  if $lines(LKF.txt) < %read.lkf { set %read.lkf 1 }
  msg # Litte Known Fact : $read(LKF.txt,n,%read.lkf)
}
Posted By: KingTomato Re: Cycling - 13/05/03 11:35 PM
on 1:TEXT:!LKF:#: {
/inc %LKF.line
/msg $chan Little Known Fact: $read(LKF.txt, %LFK.line)
}
Posted By: Nimue Re: Cycling - 13/05/03 11:42 PM
Quote:
on 1:TEXT:!LKF:#: {
/inc %LKF.line
/msg $chan Little Known Fact: $read(LKF.txt, %LFK.line)
}
This will error when all the lines in the file have been read, instead of restarting from the first line.
Posted By: codemastr Re: Cycling - 14/05/03 12:12 AM
You guys are so uncreative wink
Code:
on *:TEXT:!LKF*:#:{  
   set %read.lkf $calc((%read.lkf % $lines(LKF.txt))+1)
   msg # Litte Known Fact : $read(LKF.txt,n,%read.lkf)
}

Posted By: Raccoon Re: Cycling - 15/05/03 09:47 PM
That will consume more resources than is necessary.
Your version would read from the file twice on each use. Don't forget that $lines() is an extremely resource hungry identifier, as it has to read the entire file line by line and count each line. $lines() should be avoided wherever possible.

Code:
On *:TEXT:!LKF*:#:{     
  :BEGIN
  inc %LKF.line
  var %s = $read(LKF.txt,n,%LKF.line)
  if ( !%s ) && ( %LKF.line != 1 ) { set %LKF.line 0 | goto BEGIN }
  msg $chan Litte Known Fact: %s
}


This code may take more lines, but uses enormiously less resources. I also took infiniate looping into consideration with ( %LKF.line != 1 ), should the file be empty.

- Raccoon
© mIRC Discussion Forums