This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

random line help needed

Old posts that have not been replied to for several years.
Locked
t
thedewd

Post by thedewd »

I am trying to get a random line from a txt file to play every hour, but am stumped on what to change in the following code to make that happen. Any help would be appreciated.

# randline.tcl - read a random line to an IRC dest. every minute
for {set i 0} {$i < 60} {incr i} {bind time - "$i * * * *" readline}
proc readline {minutes hour day month year} {
set fp [open "c:/Inetpub/wwwroot/botads.txt" r]
for {set i 0} {![eof $fp]} {incr i} {set data($i) "[gets $fp]"}
close $fp

putserv "PRIVMSG #channel :$data([rand $i])"
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

For a start, there is no need to loop through a for loop, just to setup a time bind. The time bind matches by a mask, so as long as a * is there, it will run once a min.

Again, there is no need fore the for loop inside the proc, this will only confuse you.

the following should work

Code: Select all

bind time - "*" reandline
proc randline {min hour day month year} {
  set fp [open "C:/Inetpub/wwwroot/botads.txt" e]
  set temp [split [read $fp] n]
  close $fp
  puthelp "PRIVMSG #channel :[lindex $temp [rand [llength $temp]]]"
}
t
thedewd

Post by thedewd »

Thanks. That fixed it!
Locked