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.

Bracket Conflict

Help for those learning Tcl or writing their own scripts.
Post Reply
C
Conc
Voice
Posts: 6
Joined: Sat Oct 31, 2009 4:38 pm

Bracket Conflict

Post by Conc »

I made a "say" script.

it works so:

botnick say text

Part of code:

Code: Select all

putserv "PRIVMSG $c :[lrange $t 1 end]"
but this has a problem, look at this:
<Conc> Egg say [Hi]
<Egg> {[Hi]}
Why does it says {} when i type a bracket?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Because lrange operates on lists (not strings), and returns a list (not a string).
At minimum, you should use join to merge the list into a single string.
Also, if $t is simply the text you wrote to trigger the binding, then you must also use split to convert it into a list before using lrange.
NML_375
C
Conc
Voice
Posts: 6
Joined: Sat Oct 31, 2009 4:38 pm

Post by Conc »

$t isnt just the text to send... it has also the word "say".

Well... i am not very good with tcl, can you do it for me?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I suppose you'd like something like this...

Code: Select all

bind pub - "egg" someproc
proc someproc {nick host handle channel text} {
  puthelp "PRIVMSG $channel :[join [lrange [split $text] 1 end]]"
}
NML_375
C
Conc
Voice
Posts: 6
Joined: Sat Oct 31, 2009 4:38 pm

Post by Conc »

It works fine.

Thanks :)
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

I also get this problem but i use

Code: Select all

bind msg ho|ho act cmd:act
proc cmd:act {nick uhost hand arg} {
  set chan [lindex [split $arg] 0]
  set text [lrange [split $arg] 1 end]
  putserv "PRIVMSG botserv act $chan $text (Issued By $nick"
}
tried adding it like this

Code: Select all

bind msg ho|ho act cmd:act
proc cmd:act {nick uhost hand arg} {
  set chan [lindex [split $arg] 0]
  set text [join [lrange [split $arg] 1 end]
  putserv "PRIVMSG botserv act $chan $text (Issued By $nick"
}
but get error on partyline Tcl error [cmd:act]: missing close-bracket
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set text [join [lrange [split $arg] 1 end]
should be

Code: Select all

set text [join [lrange [split $arg] 1 end]]
You should also consider adding ":" before the privmsg text (i.e. "privmsg botserv :act ...").
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

Cool thanks sir_fz also changed act to :act
Post Reply