Hey, i'm trying to make my own triviascript (only found buggy ones that would crash my bot), and i want the script to count the lines in a file, and then choose a random line...anyone know how i could do this?
proc show:random { file } {
set fname [open $file r]
set num 0
while {![eof $fname]} {
incr num
set line($num) [gets $fname]
}
putloglev o * "All lines in $file: $num"
if {$num > 0} then {
putloglev o * "Random line: $line([rand $num])
}
} ;# show:random
Another way is to determine the file size, set a pointer to a random value between 0 and that file size, open the file, read the line at the random pointer and close the file.
sorry for taking it up again then..just so much work searching the old posts...
i got it fixed now...now only thing is to set the a globa variable with "the answer", so i can check it laters...
would 'set answer "mytxt"' work?
ok..thanks...sorry, dont mean to be rude when saying that i dont "bother", but earlier when i have searched, i have found like 1500 posts, and not found anything helpfull....
but thanks for answering =)