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.

TCL error

Help for those learning Tcl or writing their own scripts.
Post Reply
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

TCL error

Post by COBRa »

Hi guys struggling to get my script right i keep getting this error

[17:32:53] Tcl error [completeme]: list element in quotes followed by ":" instead of space

this is the proc

Code: Select all

proc completeme {bot com args} {
	
	set nick "User"
	set host "User@owner.irc.net"
	set hand "*"
	set chan "#somechan"
	
	set arg [lindex [lindex $args 0]]
        	
	return [isy:createtorrent $nick $host $hand $chan $arg]

}
and this is the bind

Code: Select all

bind bot - COMPLETE completeme
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Problem's probably here...

Code: Select all

set arg [lindex [lindex $args 0]]
Why do we lindex twice??
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

What do you suggest i did read something about split but to be honest im not sure
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Code: Select all

set arg [lindex [lindex $args 0]] 
$args is a string.
lindex works on lists.
You can "get away with it" sometimes, but it is not the right way to go about it.

Convert the string to a list, using
split

See: http://www.tcl.tk/man/tcl8.6/TclCmd/split.htm

Code: Select all

set arg [lindex [split $args] 0]
if you want to get the first word in $args

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Worth bookmarking and reading someday:


http://web.archive.org/web/200702051134 ... cters.html


About just what we are are talking about above.

Also has help on using timers.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Code: Select all

return [isy:createtorrent $nick $host $hand $chan $arg] 
I guess that
isy:createtorrent
is some proc that you have elsewhere. We haven't seen what is in it.
We have to hope that it doesn't have errors in it.

I don't know about having the result returned by the return command being the return of yet another proc. Maybe Spike knows if that is do-able.

What are you trying to do though? ... Why is the return command used like that?

I ask, because I'm wondering if you just want to run that other proc while passing those parameters to it.
If so, forget the use of the return command.
Just :

Code: Select all

isy:createtorrent $nick $host $hand $chan $arg
Think of
isy:createtorrent
as a new TCL command that you have created, and just use it.
(this assumes that it is a proc that is already loaded)
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Be advised that we do not support piracy, and torrents tend to be synonymous with piracy these days:
From forum rules:
No requesting help on anything involving "piracy" (of software, movies, or otherwise), because it's illegal in most places.
With that said, for those stumbling into this thread in search for information regarding list errors...
First of all, $args is actually a list. The reason is that having the last parameter in a proc declaration being named "args" makes it behave like varargs in other languages; that is, accept multiple number of arguments. Each argument will be added as a list item to $args.
Splitting $args makes absolutely no sense here.

In virtually all cases I've seen, the first fault is that people use the name "args" without knowing it's special properties.
The second fault is that they "solve" it by using lindex to extract the first item, without actually knowing why they are doing it in the first place...
NML_375
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

nml375 wrote: ...
With that said, for those stumbling into this thread in search for information regarding list errors...
First of all, $args is actually a list.
This is why I never use it, unless I mean to use it - and that is very rare.

I hate to see it, but I forced myself to leave it, since that is what it was originally. To change it, I would have had to explain why I changed it....
ugg...

The reason is that having the last parameter in a proc declaration being named "args" makes it behave like varargs in other languages; that is, accept multiple number of arguments. Each argument will be added as a list item to $args.
Splitting $args makes absolutely no sense here.
So when this bind that normally passes a text string does so, and hits the parameter named args in that place, it is converted on-the-fly from a string to a list?

Ok.. I didn't stop and even think about it at the time. I just forced myself to go with his naming.
Thanks.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

willyw wrote:So when this bind that normally passes a text string does so, and hits the parameter named args in that place, it is converted on-the-fly from a string to a list?
Well, to put it correctly, the text string is not converted into a list, but inserted as a single list element into a list.

Simply put, the string "This Test" becomes "{This Test}", and [lindex "{This Test}" 0] returns the first list item being the string "This Test".
NML_375
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

nml375 wrote: ...
Well, to put it correctly, the text string is not converted into a list, but inserted as a single list element into a list.

Simply put, the string "This Test" becomes "{This Test}", and [lindex "{This Test}" 0] returns the first list item being the string "This Test".
ahh.. ok.
Very clear.

Thank you.

And I'm sure this will all help the original poster, when he returns.
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