I don't see the connection...what's the translation of the level name to level number got in common with matching answers in a trivia script?
For the level thing:
array set s2i {chanvoice 100 chanop 200}
# let's pretend you've got the level name from the request stored in 'lev'...
if {[info exists s2i($lev)]} {
# valid level name... $s2i($lev) is the number
} else {
# invalid (unknown) level name
}
the ||'s in the ifs is there a more efficient way to do that ?
and the snippet you left works wonders (theres a set svbot(chanvoice) etc etc at the top of the code as a global)
i was just wonder ok so the user puts in the word but whatif the user places in a integer. is there a check for strings/integers? (looks at docs to see and patiently awaits a answer)
Where/how is the list $arg created?
To check for integers, use 'string is int $level' (since you check if it's empty first you don't need the -strict option)
will try what u just stated in 1 sec the arg is created via 2 ways
public command
adduser user host level
or msg
adduser chan user host level
although i asked a stupid damn question just not i don't need to check the if integer or not i just need to let it through on the integer and if its a string to make sure it matches one of the elements in the array if it doesn't send a error output to the user then return.
set arg [split $arg]
if {[llength $arg]<4} {error}
foreach {a b c d} $arg break;# creates the four variables (to match the result of the previous example)
Your expression with the ||'s could be improved by reversing it (as the first word is always empty when the last one is etc..
What's the purpose of your matches array? Why don't you use svbot directly?
EDIT: i need some rest screwed up the order of arguments in the scan
Last edited by user on Fri Jan 07, 2005 4:10 pm, edited 2 times in total.
*looks at answer with boggled eyes* ok i think i'll have a play with that so i learn to understand it and yes i can see what your point is there on the ||'s only really need the one because if there isn't 3 options typed or even 4 options
it will always fail, but still need to check the others for stuff in them hehe nice one for pointing that out.
its k, the 3 options is in the public comand which then passes its varibles to the msg command so that i don't duplicate code.the 4 check is in the msg code (chan being one of the checks)
thanx for your help i am slowly tackling your snippets and making them work for me, and learning to understand them, it is greatly reducing the number of lines of code that the proc is using