"del" {
if {[lindex $text 1] == ""} {
putdcc $idx "\002Usage\002: .randtopic <del> <topic>"
return 0
}
set found 0
set info "[lrange [split $text] 1 end]"
set file [open $topic(file) r+]
while {![eof $file]} {
set lines [split [read $file] "\n"]
foreach line $lines {
if {$line == ""} { continue }
if {$line == $info} { set found 1 }
}
}
catch {close $file}
if {$found == 1} {
putdcc $idx "Topic '$info' removed."
} else {
putdcc $idx "Topic '$info' not found."
}
}
How actualy to do the remove part? I know that I must open the file for reading, read all lines from the file except the line I want to be removed and then close the file and open it again for writing, or open it once and do the reading and writing part. I've did some tests and got stucked..
Once the game is over, the king and the pawn go back in the same box.
Your while loop is a bit confused. If you're using [read $file] then that will read in the entire file -- you don't need another loop.
Then your foreach loop can be easily replaced with lsearch and it will make more sense. Right now you set found to 1, but you don't save the line number. How do you know which line to remove?
Finally, you have to rewrite the file, just like you said. To do that, open the file in write mode, and puts -nonewline [join $lines \n].
Hi, thanks fotr your reply. I've already figured out what I must do and seems that I've succided. I'll follow your instructions and do one and compare wich one is the best one.
Once the game is over, the king and the pawn go back in the same box.