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.

help with read/output file, public trigger

Help for those learning Tcl or writing their own scripts.
Post Reply
i
iNFERNiS
Voice
Posts: 13
Joined: Tue Aug 21, 2007 11:03 am

help with read/output file, public trigger

Post by iNFERNiS »

I'm very new to tcl and coding in general. I wanted to make a simple script that reads from a textfile, grabs a random line and outputs it to a channel, with a public trigger.

Suffice to say i failed horribly, i'm kind of stuck now. Can someone point me into the right direction?
bind pub o|o !randtext pub:randtext

proc pub:randtext { } {
putserv "PRIVMSG $channel : randline("randomness.txt")"
}

proc randline {file} {
set fs [open $file r]
set data [read -nonewline $fs]
close $fs
return [lindex $data [expr {int(rand()*[llength $data])}]]
}
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Start off with a basic TCL tutorial first, your code doesn't look like TCL to me :p
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Here's a basic script for reading text and spitting out random lines:
http://members.dandy.net/~fbn/jokes.tcl.txt
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

metroid wrote:Start off with a basic TCL tutorial first, your code doesn't look like TCL to me :p
That was rude :D
|AmDeAtH @ Undernet
Death is only the *Beginning*...
Post Reply