mIRC Home    About    Download    Register    News    Help

Print Thread
#24038 13/05/03 11:16 PM
Joined: Apr 2003
Posts: 6
V
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
V
Joined: Apr 2003
Posts: 6
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.

#24039 13/05/03 11:34 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
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)
}

#24040 13/05/03 11:35 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
on 1:TEXT:!LKF:#: {
/inc %LKF.line
/msg $chan Little Known Fact: $read(LKF.txt, %LFK.line)
}


-KingTomato
#24041 13/05/03 11:42 PM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
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.

#24042 14/05/03 12:12 AM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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)
}


#24043 15/05/03 09:47 PM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
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


Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Link Copied to Clipboard