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.

switch help

Help for those learning Tcl or writing their own scripts.
Post Reply
v
veblen
Voice
Posts: 18
Joined: Tue Mar 13, 2007 11:23 am

switch help

Post by veblen »

im only quite new to tcl scripting, and i want to set a switch to use as variables within a proc. im not too sure how to do this properly, so if someone could just give me a quick example.

on command in channel !select, i want to use a switch to give me a variable number. so the line in a channel would be:

!select --n20 rest of the text string here

i want to use whatever number after --n as the variable to use in the rest of the proc, and i need the rest of the text string in a variable too.
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

bind pub - !select pub:select

proc pub:select {nick uhost hand chan arg} {
 # --n# 
 set switch [lindex [split $arg] 0]
 # if switch is not --n<number> then return
 if {![regexp -- {--n[0-9]{1,}} $switch]} {return 0}
 # take the number after --n
 set num [string range $switch 3 end]
 # take the rest
 set rest [join [lrange [split $arg] 1 end]]
 switch -- $num {
  1 {
   # the number is 1, do whatever
  }
  2 {
   # the number is 2, do whatever
  }
  default {
   # any other number
  }
 }
}
Post Reply