mIRC Homepage
Posted By: acemiles_ed Randomize Read? - 01/03/03 03:45 PM
Lets say I have a text file that looks like this:
Code:
ed said hi to kat this morning
john waved at ed this afternoon
bill saw kat last night :x
kat wasn't amused


Is there a way to make $read(file.txt, s, kat) to be randomized, so that on the first $read, it gives 'ed said hi to kat this morning', but on the second it would give 'kat wasn't amused' ...?

Example two: $read(file.txt, s, this) would return a line (randomly?) with the word 'this' in it.

Thanks,
-ed
Posted By: Cheech Re: Randomize Read? - 01/03/03 03:47 PM
//echo $read(funny.txt)

Reads a random line from the file funny.txt.

ah nevermind i see you have happy and sad in the file using the -s switch is going to scan the file for a line with happy assuming that it prolly scans from top to bottom it will hit the same line each time you might try using the $readn value to exclude that line in the next call ? or simply make more than one .txt file happy.txt sad.txt etc..
Posted By: acemiles_ed Re: Randomize Read? - 01/03/03 04:03 PM
Well... it would actually be used for a quotes script, and I was hoping that users would be able to type !quote <anything> and it would randomly search for a line with the <word> in it.
Posted By: Cheech Re: Randomize Read? - 01/03/03 04:07 PM
well it takes a little longer but you could still seperate it into catagories happy, sad, silly, etc.. just type !quote *whatver* then go to the coresponding file ?
Posted By: acemiles_ed Re: Randomize Read? - 01/03/03 04:11 PM
Well.. I guess my text file example was not very specific... I *could* split it into a bunch of categories, but some may fall in both, and I could end up having 400 txt files with all the possible search terms... I will edit my first post with a better text file example..
Posted By: Collective Re: Randomize Read? - 01/03/03 05:01 PM
My suggestion, but havent tested for bugs...:
Code:
on *:TEXT:!quote*:#:{
  var %l = 1
  var %c = 0
  while ( $read([color:green]quote.txt[/color],w,* $+ $2 $+ *,%l) != $null ) {
    inc %l
    inc %c
  }
  msg $nick $read([color:green]quote.txt[/color],w,* $+ $2 $+ *,$rand(1,%c))
}

Posted By: qwerty Re: Randomize Read? - 01/03/03 06:36 PM
A much faster way (and this is important, since it's a remotely triggered routine) is to use /filter to grab all lines and dump them to a hidden custom window, then select a random line from that window.
Code:
on *:text:!quote ?*:#:{
  window -h @@
  filter -fwc quotes.txt @@ * $+ $2*
  if $filtered { msg $nick $line(@@,$rand(1,$ifmatch)) }
  close -@ @@
}
Posted By: acemiles_ed Re: Randomize Read? - 01/03/03 07:10 PM
Thanks to everyone for their help!
© mIRC Discussion Forums