Bind: same proc, different arguments

Help for those learning Tcl or writing their own scripts.
Post Reply
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Bind: same proc, different arguments

Post by boehmi »

Hi,

is there a possibility for calling the same procedure with different arguments with bind pub?

Like:
bind pub "-|-" !test1 proc1 "test1"
bind pub "-|-" !test2 proc1 "something else"
bind pub "-|-" !test3 proc1 "lalala"

Thanks for your help
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Bind: same proc, different arguments

Post by user »

Code: Select all

bind pub - !test1 [list proc1 test1]
bind pub - !test2 [list proc1 "something else"]
proc proc1 {addedArg nick uhost hand chan arg} {...}
Have you ever read "The Manual"?
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Post by boehmi »

thank you very much, but what if i additionally want to get the arguments?

e.g.
!test1 10
!test1 20
!test2 20

something like
bind pub - !test1 [list proc1 $args test1]
bind pub - !test2 [list proc1 $args "something else"]
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You just use the last variable (arg in user's example):

Code: Select all

bind pub - !test1 proc1
proc proc1 {nick host handle channel arg} {
  puthelp "PRIVMSG $channel :Hey $nick, thanks for the $arg"
}
The above example will make your eggie echo back whatever people pass as an argument with !test1. If we were to extend this with the previous code, it'd probably look a little like this:

Code: Select all

bind pub - !test1 [list "proc1" "test1"]
bind pub - !test2 [list "proc1" "test2"]
proc proc1 {custom nick host handle channel arg} {
  if {$custom == "test1"} {
    puthelp "PRIVMSG $channel :Hey $nick, thanks for the $arg"
  }
  puthelp "PRIVMSG $channel :*waves*"
}
Here with the added feature that it'll do the echo only for !test1, but the *waves* for both !test1 and !test2.
NML_375
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Post by boehmi »

Ah ok... i thougth the
  • version would overwrite the default parameters.

    Thanks a lot
Post Reply