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 for those learning Tcl or writing their own scripts.
EVRAMP
Voice
Posts: 7 Joined: Fri Apr 28, 2006 9:13 am
Location: /home/czech_republic/
Post
by EVRAMP » Fri Apr 28, 2006 9:54 am
Hi,
i made script which sends jokes to channel form file joke.txt, but it doesnt work.
Here is source:
Code: Select all
bind pub - !joke pub:joke
bind pub w !addjoke pub:addjoke
proc pub:addjoke { nick uhost handle channel arg } {
if { $arg == "" } {
putserv "NOTICE $nick :USAGE: !addjoke <joke>"
return 0
}
set joke [open "joke.txt" a]
puts $joke "$arg"
close $joke
putserv "NOTICE $nick :joke added"
}
proc pub:joke { nick uhost handle channel arg } {
set jokefile [open "joke.txt" r]
set i 0
while { [eof $jokefile] != 1 } {
incr i 1
set joke($i) [gets $jokefile]
}
set w [rand $i]
set outjoke $joke($w)
putserv "PRIVMSG $channel :$outjoke"
}
putlog "joke.tcl successfully loaded"
Please can you help me where i did mistake? Thx!
metroid
Owner
Posts: 771 Joined: Wed Jun 16, 2004 2:46 am
Post
by metroid » Tue May 02, 2006 11:40 am
What's the error then?
EVRAMP
Voice
Posts: 7 Joined: Fri Apr 28, 2006 9:13 am
Location: /home/czech_republic/
Post
by EVRAMP » Wed May 03, 2006 9:21 am
the one and only error is that it doesnt work. bot doesnt send a joke to channel x|
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Wed May 03, 2006 10:35 am
post the information from
you need to show the error(s) you get
EVRAMP
Voice
Posts: 7 Joined: Fri Apr 28, 2006 9:13 am
Location: /home/czech_republic/
Post
by EVRAMP » Sat May 06, 2006 5:31 pm
Tcl error [pub:joke]: can't read "joke(0)": no such element in array
metroid
Owner
Posts: 771 Joined: Wed Jun 16, 2004 2:46 am
Post
by metroid » Sat May 06, 2006 5:47 pm
it's because your incr before setting it.
Place the incr after it and it should work fine
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Sun May 07, 2006 2:58 am
why not simply use 'lappend joke [gets $jokefile]' and '[lindex $joke $w)]' instead of those arrays? If the file ends with an empty line, this will also be included, but could be removed with an lreplace or even more simple, lower i by 1, so it cannot be chosen (should be considered for a bigger file to lower memory usage).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under
The MIT License
Love hurts, love strengthens...