set i 0
lappend game ""
set id [array startsearch alias]
while {[array anymore alias $id]} {
set item [array nextelement alias $id]
set ding [split $item #]
set type [lindex $ding 0]
set number [lindex $ding 1]
set ${type}game($number) "$alias($item)"
if {$type == "jkja"} { putchan $chan "debug1: ${type}game($number)" }
lappend num $i
lappend output $type
if {[lsearch -all $game $type] >= 1} {
continue
} else {
lappend game $type
}
incr i
}
The problem is that in the 'if {$type == "jkja"}' line the output of the putchan is jkjagame(1) rather then what that value holds, if i change ${type}game($number) into $jkjagame($number) it works and displays just that what the array value holds...
A couple ways to do it. Maybe the easiest way is to use the set command. It returns the value of the variable you give it, so you can do more advanced substitution using it:
Another way to do it is with upvar, especially if it's a global variable. You create a link to the array and then manipulate it as if it were the other variable.
proc doit {} {
set type green
set var hunger
upvar #0 ${type}dragon link
set link($var) "sheep"
}
now global greendragon(hunger) = sheep
The same thing works for local variables, using 0 instead of #0 in upvar.
You can also do tricks like the set one with subst and eval:
set type green
set a [subst $${type}dragon(hunger)]
eval set b $${type}dragon(hunger)
now $a = $b = sheep
You are entering the dark side of tcl scripting. Don't let its power draw you in!