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.

How to split this !nick <name> <mail> <text&g

Old posts that have not been replied to for several years.
Locked
m
minotaur
Voice
Posts: 19
Joined: Sun Jul 06, 2003 8:36 pm

How to split this !nick <name> <mail> <text&g

Post by minotaur »

HI i have a script like this

bind pub - "!nick" add

proc add { nick idx handle chan args } {
set name [lindex $args 0]
set email [lindex $args 1]
set text [lindex $args 2 end]

puthelp "NOTICE $nick :Hi $name with $email added and $text"
}

but now the notice is if i type: !nick mino mino@mino.com mino is cool
he says per Notice "Hi mino
mino@mino.com
mino is cool with added and "

What my fault?? PLz help me :-? :wink:
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

your lindex $args are not correct, try fixin them.
like set name [lindex $args 0] for example will read with spaces (i think) so u have to make it read only the first word.
m
minotaur
Voice
Posts: 19
Joined: Sun Jul 06, 2003 8:36 pm

Post by minotaur »

Yes i know it but how can i split it after each SPACE into another variable?
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

Code: Select all

bind pub - !nick add
proc add { nick host handle chan arg } {
set arg [split $arg] 
set name [lindex $arg 0] 
set email [lindex $arg 1] 
set text [lindex $arg 2 end] 
puthelp "NOTICE $nick :Hi $name with $email added and $text" 
}
stuff:

name vars appropriately :)
"args" has special meaning in tcl, dont use it 'til you know what it does
"split" splits at <space> unless something else is specified
photon?
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set text [lindex $arg 2 end]
this should be

Code: Select all

set text [join [lrange $arg 2 end]]
Elen sila lúmenn' omentielvo
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

oops :o
photon?
m
minotaur
Voice
Posts: 19
Joined: Sun Jul 06, 2003 8:36 pm

Post by minotaur »

But now the variable $name and $text (1st and Last Variable) has a leading { or a in $text atleast a } ??

How can i cut the first char out in $name
and the last in $text ?

or can someone post me a function that has that alreasy implemented?
m
minotaur
Voice
Posts: 19
Joined: Sun Jul 06, 2003 8:36 pm

Hmm no one any answer for me how?

Post by minotaur »

Hmm no one any answer for me how?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Stop using the variable name "args" if you don't need it / know what it does. (read about it here: http://tcl.tk/man/tcl8.4/TclCmd/proc.htm )
Locked