Posted to tcl by patthoyts at Sat Dec 09 19:18:56 GMT 2006view raw

  1. proc InitNickState {nick level somethingelse} {
  2. variable uid
  3. set State [namespace current]::nick[incr uid]
  4. upvar #0 $State state
  5. set state(nick) $nick
  6. set state(level) $level
  7. set state(somethingelse) $somethingelse
  8. return $State
  9. }
  10.  
  11. Then to use it:
  12.  
  13. proc CheckLevel {nick} {
  14. foreach State [info vars [namespace current]::nick*] {
  15. if {[set [set $State](nick)] eq $nick} {
  16. return [set [set $State](level)]
  17. }
  18. return -code error "nick not found"
  19. }
  20.  
  21. or if you keep the State array id you can use
  22. proc Level {State) {
  23. upvar #0 $State state
  24. return $state(nick)
  25. }