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.

[SOLVED] Tcl error: wrong # args

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Landslyde
Halfop
Posts: 46
Joined: Thu May 01, 2014 6:01 pm

[SOLVED] Tcl error: wrong # args

Post by Landslyde »

I'm new to TCL scripting. When I want my bot to do something, I find a script to learn from. That said, here I am. Stuck!

My code is:

Code: Select all

bind pub - .lovesme pub_lovesme

set lovesme1 {
	"is in deep love with you, "
	"loves loves loves you, "
}

proc pub_lovesme {nick host handle channel arg} {
	global lovesme1
	set lovesme2 [lindex $lovesme1 [rand [llength $lovesme1]]]
	set mychanlist [chanlist $channel]
	set randomnick [lindex $mychanlist [rand [llength $mychanlist]]]
	putserv "PRIVMSG $channel :$randomnick $lovesme2 $nick" randomnick lovesme2
	return 1
}
But this fails and i get:

Code: Select all

Tcl error [pub_lovesme]: wrong # args: should be "putserv text ?options?"
What am I doing wrong? Any help wld be appreciated. Thanks.
Last edited by Landslyde on Thu Apr 14, 2016 1:32 am, edited 1 time in total.
L
Landslyde
Halfop
Posts: 46
Joined: Thu May 01, 2014 6:01 pm

Post by Landslyde »

Never mind. I figured it out. I added this to concatenate the two vars:

Code: Select all

{
...
set lovemsg $randomnick$lovesme2
putserv "PRIVMSG $channel :$lovemsg $nick" lovemsg
return 1
}
Sure. This is cheesy stuff, but the girls wanted it. What can I say :P

Peace out...
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

lol, you were just declaring to variables after it has been processed and put to channel.

Code: Select all

putserv "PRIVMSG $channel :$randomnick $lovesme2 $nick" randomnick lovesme2 
So, your code was fine :)
I only added a small substitution so that you could use $nick $chan arguments within your set list, and a check to make sure randomnick wasn't botnick (and if it was, just send a silly message to chan).

Code: Select all

bind pub - .lovesme pub_lovesme

set lovesme1 {
   "is in deep love with you, $nick"
   "loves loves loves you, $nick"
   "only loves loves $chan ..."
}

proc pub_lovesme {nick uhost hand chan arg} {
   global lovesme1
   set lovesme2 [lindex $lovesme1 [rand [llength $lovesme1]]]
   set lovesme2 [subst -nocommands $lovesme2]
   set mychanlist [chanlist $chan]
   set randomnick [lindex $mychanlist [rand [llength $mychanlist]]]
   if {[isbotnick $randomnick]} {puthelp "PRIVMSG $chan :Sorry, $nick, but bot love leads to botulism.."; return}
   puthelp "PRIVMSG $chan :$randomnick $lovesme2"
   return 0
}
Alternatively, to remove the botnick completely, and avoid the above isbotnick check, use:

Code: Select all

set mychanlist [chanlist $chan]
set rembot [lsearch $mychanlist $::botnick]
set mychanlist [lreplace $mychanlist $rembot $rembot]
set randomnick [lindex $mychanlist [rand [llength $mychanlist]]]
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
L
Landslyde
Halfop
Posts: 46
Joined: Thu May 01, 2014 6:01 pm

Post by Landslyde »

Get_A_Fix:

Thanks for your reply. What I ended up doing was this:

Code: Select all

# Start of pub_lovesme
proc pub_lovesme {nick host handle channel arg} {
	global loves0 loves1 emo1
	set emo2 [lindex $emo1 [rand [llength $emo1]]]
	set loves00 [lindex $loves0 [rand [llength $loves0]]]
	set loves2 [lindex $loves1 [rand [llength $loves1]]]
	set mychanlist [chanlist $channel]
	set randomnick [lindex $mychanlist [rand [llength $mychanlist]]]
	if { $loves2 != "" } {
		set lovemsg $loves00$randomnick$loves2$nick$emo2
		putserv "PRIVMSG $channel :$lovemsg" lovemsg
		return 1
	} else {
		putserv "PRIVMSG $channel :Sorry, $nick, but no one loves you."
		return 1
	}
}
# End of .lovesme
Works like a charm. But I appreciate you showing me how to exclude the bot.

One of the things that puzzles me is the usages of:

Code: Select all

putserv
puthelp
putquick
I may have left some off, but I don't understand the differences, if any, between those.
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

Landslyde wrote:Get_A_Fix:

One of the things that puzzles me is the usages of:

Code: Select all

putserv
puthelp
putquick
I may have left some off, but I don't understand the differences, if any, between those.
The difference is merely queue, where putserv (sending commands to server) has the highest sending queue, puthelp (sending commands to channel/nickname) has less, and putquick (sending commands as fast as queue allows) is for limited output as to not excess flood the bot offline.
Info about these queues, and other's (like putnow..) can be found in your doc/tcl-commands.doc file, shipped with your eggdrop.

Good luck! Keep coding :)
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
L
Landslyde
Halfop
Posts: 46
Joined: Thu May 01, 2014 6:01 pm

Post by Landslyde »

Get_A_Fix:

Much appreciated. Especially the info on the doc/tcl-commands.doc file. That's my next stop.

Have a good one.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Landslyde wrote: ...
the doc/tcl-commands.doc file. That's my next stop.

...

Also found here:
http://www.eggheads.org/support/egghtml ... mands.html

I find it handy to view/read/search it online, myself.
I think this is the current version. Maybe someone else can comment on this.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Post Reply