for {set count 0} {$count<$num_of_UEs} { incr count } {
puts $count
set tcp$count [new Agent/TCP]
#$tcp$count set fid_ $count
#$tcp$count set prio_ 2
}
我的問題是與線#$tcp$count set fid_ $count
當我試着執行它時,它說有什麼不對本聲明
can't read "tcp": no such variable
while executing
"$tcp$count set fid_ $count"
("for" body line 4)
invoked from within
"for {set count 0} {$count<$num_of_UEs} { incr count } {
puts $count
set tcp$count [new Agent/TCP]
$tcp$count set fid_ $count
$tcp$coun..."
它說無法讀取TCP,以及它不應該閱讀TCP應該讀它在第一次迭代中爲tcp0,在第二次中爲tcp1,依此類推。 什麼是我做錯了?
感謝
編輯:
我使用數組,謝謝你的提示嘗試。它的工作的大部分地區,但在一個特定的情況下 當我這樣做:
for {set count 0} {$count<$num_of_UEs} { incr count } {
set ftp($count) [new Application/FTP]
$ftp($count) attach-agent $tcp($count)
}
它給了我下面的錯誤:
Came here 0
(_o180 cmd line 1)
invoked from within
"_o180 cmd target _o99"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o180" line 2)
(SplitObject unknown line 2)
invoked from within
"$agent target [[$self node] entry]"
(procedure "_o98" line 2)
(RtModule attach line 2)
invoked from within
"$m attach $agent $port"
(procedure "_o97" line 4)
(Node add-target line 4)
invoked from within
"$self add-target $agent $port"
(procedure "_o97" line 15)
(Node attach line 15)
invoked from within
"$node attach $agent"
(procedure "_o3" line 2)
(Simulator attach-agent line 2)
invoked from within
"$ns attach-agent $node2 $tcp($count)"
("for" body line 3)
invoked from within
"for {set count 0} {$count<$num_of_UEs} { incr count } {
puts "Came here $count"
$ns attach-agent $node2 $tcp($count)
}"
(file "hsexample.tcl" line 104)
我知道它很長,但我會很感激你幫助
雖然,數組是一個更易讀的選擇:'$ tcp($ count)' – 2011-04-18 10:50:23
@Bryan:當然可以。我應該提到這一點。 – bmk 2011-04-18 12:15:40