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.

Simple, but yet an error!

Help for those learning Tcl or writing their own scripts.
Post Reply
T
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Simple, but yet an error!

Post by T-Xorcist »

When I enter the following code:

Code: Select all

bind msg n kick trap_msg

proc trap_msg {nick uhost hand text} {
  set whom [lindex $text 0]
  set where [lindex $text 1]
  if {[onchan $whom $where]} {
    putquick "KICK $where $whom :Requested"
  } else {
    putquick "NOTICE $nick: \002$whom\002 zit niet in \002$where\002"
  }
}
it will give this error in my log file:

Code: Select all

Tcl error [trap_msg]: wrong # args: should be "trap_msg nick uhost hand text"
What am I doing wrong and could someone give me more information howto know what and when you need sertain args?

Thanks!
T
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Post by T-Xorcist »

Code: Select all

bind msg n kick trap_msg

proc trap_msg {nick uhost hand text args} {
  set where [lindex $text 0]
  set whom [lindex $text 1]
  if {[onchan $whom $where]} {
    putquick "KICK $where $whom :Requested"
  } else {
    putquick "NOTICE $nick: \002$whom\002 zit niet in \002$where\002"
  }
}
Well this works, but can anyone explain we how to use the args and when?
Example above: {nick uhost hand text args}
F
FTL25
Voice
Posts: 17
Joined: Mon Nov 14, 2005 5:39 pm

Post by FTL25 »

From _SunMar_ 's tut @ SUNiNET:
The syntax of the proc command is proc <name> { <parameters> } { <body> }.

The <parameters> are the variables the procedure must put its received parameters in.

You need to specify a variable for each parameter here that will be sent to the procedure. All the variables you give have to be seperated by spaces.

...

There is one exception to this rule though. If you call the last variable of <parameters> "args" than you may call upon the procedure with more parameters than you have defined in <parameters>.

In this case all of the parameters you give to the procedure up from the point where the argument "args" start is put in $args. They are put into $args as if the list command was used to make $args.
Maybe that will help...
Post Reply