egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A Short Joke Script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
EVRAMP
Voice


Joined: 28 Apr 2006
Posts: 7
Location: /home/czech_republic/

PostPosted: Fri Apr 28, 2006 9:54 am    Post subject: A Short Joke Script Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Tue May 02, 2006 11:40 am    Post subject: Reply with quote

What's the error then?
Back to top
View user's profile Send private message
EVRAMP
Voice


Joined: 28 Apr 2006
Posts: 7
Location: /home/czech_republic/

PostPosted: Wed May 03, 2006 9:21 am    Post subject: Reply with quote

the one and only error is that it doesnt work. bot doesnt send a joke to channel x|
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Wed May 03, 2006 10:35 am    Post subject: Reply with quote

post the information from
Code:
.set errorInfo


you need to show the error(s) you get
Back to top
View user's profile Send private message
EVRAMP
Voice


Joined: 28 Apr 2006
Posts: 7
Location: /home/czech_republic/

PostPosted: Sat May 06, 2006 5:31 pm    Post subject: Reply with quote

Tcl error [pub:joke]: can't read "joke(0)": no such element in array
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Sat May 06, 2006 5:47 pm    Post subject: Reply with quote

it's because your incr before setting it.

Place the incr after it and it should work fine
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun May 07, 2006 2:58 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber