The idea of that script is to store the line that are read and to check that the line hasn't been read before validating

It uses a variable which is a bit too simple and will end up being wrong if you have too many lines, a quick hash table with the $hash of the line will work better:

Code:
alias randomline {
  var %h randomline $+ $hash($1,32),%ok
  if ($2 == clear) hfree %h
  else {
    var %r $read($1,$2),%l $hash(%r,32)
    while ($hget(%h,%l)) var %r $read($1,$2),%l $hash(%r,32)
    if (!$hget(%h,%l)) {
      hadd -m %h %l 1
      %ok = 1
    }
    if ($hget(%h,0).item == $lines($1)) hfree %h
    if (%ok) returnex %r
  }
}
and just use $randomline(file,<clear|tn>) if you pass clear as the second parameters, it will clear the table and forget the lines already read, to start again. This process is done automatically if it detects that you read all the lines, (this might not work if you edit the file without clearing the table), otherwise you can use this parameter to pass the 't' or 'n' switch to the $read call, which is recommended.

Last edited by Wims; 09/05/15 08:29 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel