mIRC Home    About    Download    Register    News    Help

Print Thread
#202418 22/07/08 12:06 AM
Joined: May 2003
Posts: 3
I
ircron Offline OP
Self-satisified door
OP Offline
Self-satisified door
I
Joined: May 2003
Posts: 3
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.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
If you think that $filtered is returning a crazy value, add a debug display line to see what the filter command is seeing. i.e. just above the

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

... line add a line like:

echo -s $nopath($script) $scriptline filter -ff %randq.file %randq.tempfile %randqs.text

I assume your $mircdir doesn't have any spaces within the path, as that would mess up your script without using quotes when referencing your filename. You might also wish to filter into a @custom window instead of a tempfile, since that makes it a whole lot easier to see what's going in in your temp file.

Joined: May 2003
Posts: 3
I
ircron Offline OP
Self-satisified door
OP Offline
Self-satisified door
I
Joined: May 2003
Posts: 3
Oh crap, I was doing a return before calling cleanuprandq. OOPS!

Yep. Fixed it.

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

Link Copied to Clipboard