| View previous topic :: View next topic |
| Author |
Message |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Thu Sep 29, 2016 12:43 pm Post subject: TCL error |
|
|
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: | 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: | | bind bot - COMPLETE completeme |
|
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Thu Sep 29, 2016 1:16 pm Post subject: |
|
|
Problem's probably here... | Code: | | 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
. |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Thu Sep 29, 2016 1:23 pm Post subject: |
|
|
| What do you suggest i did read something about split but to be honest im not sure |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Sep 29, 2016 1:39 pm Post subject: |
|
|
| Quote: |
| Code: |
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: |
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 ! |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Sep 29, 2016 1:54 pm Post subject: |
|
|
| Quote: |
| Code: |
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: |
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 ! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Sep 29, 2016 4:28 pm Post subject: |
|
|
Be advised that we do not support piracy, and torrents tend to be synonymous with piracy these days:
From forum rules:
| Quote: | | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Sep 29, 2016 6:02 pm Post subject: |
|
|
| 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...
| Quote: |
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 ! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Sep 29, 2016 6:23 pm Post subject: |
|
|
| 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Sep 29, 2016 6:27 pm Post subject: |
|
|
| 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 ! |
|
| Back to top |
|
 |
|