set position [expr [rand [llength [chanlist $chan]]] + 1]
since list commands are zero-based, the llength is always "last element index+1" and since rand returns a number between 0 and the supplied integer-1 no expr is needed.
Keep in mind that an empty chanlist might be returned and cause rand to error on you (depending on what triggered the code of course), so you better check the llength first (or use expr rand() to do the randomizing)
set spin_list [chanlist $chan]
set spin_list [lreplace $spin_list $nick $nick]
set spin_list [lreplace $spin_list $botnick $botnick]
set spin_length [llength $spin_list]
if {[$spin_length == 0]} {
putserv "PRIVMSG $chan :You need more players"
return 0
}
set spin_num [rand $spin_length]
set spin_nick [lindex $spin_list $spin_num]
I am still working on that script for kaamal
I once was an intelligent young man, now i am old and i can not remember who i was.
The set spin_num [rand $spin_length] should be set spin_num [expr [rand $spin_length] +1] because of the rand. Example: rand 10 will allways be a number from 0 to 9 so.. by adding 1 to the result of the rand actualy is a random number from 1 to 10 inccluding 1 and 10, as it should be.
Once the game is over, the king and the pawn go back in the same box.
Umm.. you haven't got my point. I've said that the rand thing makes it choose a random number from 0 to the number you've have choosen to get a random number from it except it. Also, I do agree with you on the list part, I haven't said that the list part is wrong or something..
Once the game is over, the king and the pawn go back in the same box.
Nothing, after I've posted I've thinked a bit on the thinkgs stdragon said and he and now you where right. the lindex makes it be correct.. My appologies for that.
Once the game is over, the king and the pawn go back in the same box.