| View previous topic :: View next topic |
| Author |
Message |
veblen Voice
Joined: 13 Mar 2007 Posts: 18
|
Posted: Sat Mar 17, 2007 1:23 pm Post subject: switch help |
|
|
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. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Mar 17, 2007 1:48 pm Post subject: |
|
|
| Code: | 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
}
}
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|