Okay, to preface, I'm trying to write a simple function that searches a text file with IRC quotes, isolates all lines containing optional matchtext, and returns a random quote from the resulting filtered lines. I'm using a tempfile to do this, but I get weird results.

$filtered is supposed to return the number of lines filtered isn't it? And then I will do the function several times, and the line count on the temporary file is always different, so it's not even filtering correctly. If I'm doing something stupid, someone let me know.. (Yes, I have those first load variables set up correctly, that's not the issue...)

Here is the script:
-----------
Code:
 
on 1:load:{
  ; Set up global variables to be used by script. 
  set -n %randq.file c:\ron\quotes
  set -n %randq.tempfile $mircdir $+ tempquotes
}

alias getrandq {
  ; If a matchtext is not specified, just return a random line
  ; from file. 
  if ($1 == $null) {
    cleanuprandq 1
    return $read(%randq.file)
  }

  set %randqs.text $1-

  filter -ff %randq.file %randq.tempfile %randqs.text

  echo -a filtered = $filtered
  echo -a lines in temp = $lines(%randq.tempfile)

  ; Make sure we have some data waiting in our tempfile. 
  ; Since $filtered doesn't seem to work correctly, we can't
  ; provide extra stats like MatchUsed/Matches/TotalQuotes.
  if ($filtered == 0) { 
    cleanuprandq 1
    return No match $+ ( $+ es $+ ) found.
  }

  set %randqs.quote $read(%randq.tempfile) 

  ; Make sure matches are found. In theory, this block of 
  ; code will never be used. 
  if ($readn == 0) {
    cleanuprandq
    return No match $+ ( $+ es $+ ) found.
  }
  return %randqs.quote
  cleanuprandq 
}

alias -l cleanuprandq {
  ; Clean up after ourselves. 
  ; Only remove tempfile if there is one waiting. The caller 
  ; decides by sending "1" as a parameter to cleanuprandq if
  ; there is NOT a file to be deleted (since this case happens
  ; less frequently). 
  if ($1 != 1) { .remove %randq.tempfile }
  unset %randqs*
}


Last edited by ircron; 22/07/08 12:22 AM.