| View previous topic :: View next topic |
| Author |
Message |
EVRAMP Voice

Joined: 28 Apr 2006 Posts: 7 Location: /home/czech_republic/
|
Posted: Fri Apr 28, 2006 9:54 am Post subject: A Short Joke Script |
|
|
Hi,
i made script which sends jokes to channel form file joke.txt, but it doesnt work.
Here is source:
| Code: | 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! |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Tue May 02, 2006 11:40 am Post subject: |
|
|
| What's the error then? |
|
| Back to top |
|
 |
EVRAMP Voice

Joined: 28 Apr 2006 Posts: 7 Location: /home/czech_republic/
|
Posted: Wed May 03, 2006 9:21 am Post subject: |
|
|
| the one and only error is that it doesnt work. bot doesnt send a joke to channel x| |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Wed May 03, 2006 10:35 am Post subject: |
|
|
post the information from
you need to show the error(s) you get |
|
| Back to top |
|
 |
EVRAMP Voice

Joined: 28 Apr 2006 Posts: 7 Location: /home/czech_republic/
|
Posted: Sat May 06, 2006 5:31 pm Post subject: |
|
|
| Tcl error [pub:joke]: can't read "joke(0)": no such element in array |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Sat May 06, 2006 5:47 pm Post subject: |
|
|
it's because your incr before setting it.
Place the incr after it and it should work fine |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun May 07, 2006 2:58 am Post subject: |
|
|
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... |
|
| Back to top |
|
 |
|