Quote:
Hello, I have a complicated seen script, and I just have a problem, so I'm only showing edited parts of it for easy understanding.

Code:
on *:text:*:*: { 
    write -w" [ $nick ] $+ :*" seen.txt $nick $+ : $+ [ $ctime ] $+ : $+ [ $chan ] $+ :saying " $+ [ $1- ] $+ "
}


Code:
alias seen {
  var %temp, %chan, %nick
  %nick = $1
  %chan = $2
  %seennick = $3
  %temp = $read(seen.txt,w,%seennick $+ :* )
  if (%temp) {
    tokenize 58 %temp
    if ($1 == %nick) { 
      /msg %chan %nick $+ : there you are!
    }
    else { 
    /msg %chan %nick $+ : I last saw $+ $1 $+ in $+ $3 $+ $duration($calc($ctime - $2)) ago, $4- }
  }
  else { 
    /msg %chan %nick $+ : I've never seen $+ %seennick $+ in $+ $2 $+ before. }
  }
}


So let's say I someone says 'word 1' then the seen would return, 'word 1' Then let's say someone says 'word 2' etc.

But how do I get it to return the second or third last line?

In seen.txt, it will look like:


Neal:1124335052:#channel1:saying "word 2"
Neal:1119168890:#channel1:saying "word 1"

Notice the ctime, it is not in chronological order.

So the problem with this is:

%temp = $read(seen.txt,w,%seennick $+ :* )

I have tried

%temp = $read(seen.txt,w,%seennick $+ :*, $calc($readn +1) )

And

%temp = $read(seen.txt,w,%seennick $+ :*, $calc($readn -1) )

So, how would I return the second last line, and, how do I /write this in chronological order?

Thanks.

For writing in chronological order you have to use /filter:
Code:
filter -fftu 2 58 seen.txt seen2.txt
if ($exists(seen2.txt)) {
.remove seen.txt
.copy seen2.txt seen.txt
.remove seen2.txt
}

Also there is one more bug, which exists in most scripts that are using the $read() or $readini().
Quote:

If the n switch is specified then the line read in will not be evaluated and will be treated as plain text.

If you don't use this switch at read, the read line will be evaluated. And if i type on channel:
a $findfile(.,*,1,quit) b
!seen stefys
will make the bot quit smile