Instead of that, define the sink as an array variable and use it as normal
http://wiki.tcl.tk/1032


####

set sink(1)             [new Agent/TCPSink]

...

Proc something { }  {
        global sink

        ...
        set bw0 [$sink(1) set bytes_]

}

> -----Original Message-----
> From: Renata Vidal [mailto:[EMAIL PROTECTED]
> Sent: sexta-feira, 29 de Setembro de 2006 20:48
> To: [EMAIL PROTECTED]
> Cc: ns-users
> Subject: Re: [ns] LossMonitor - can't read, no such variable
> 
> My variables are called sink($i), the () is in the name of them. I
> tried scape it but it not solve the problem. If I change for something
> like sink$i I have errors on attach-agent command.
> This example below don't works for me...
> Any clue?
> 
> On 9/29/06, Pedro Vale Estrela <[EMAIL PROTECTED]> wrote:
> > Ahh, the ever challenging TCL syntax...
> >
> > a) Check Frequently Made Mistakes™ in Tcl
> > http://phaseit.net/claird/comp.lang.tcl/fmm.html
> >
> > b) try like this:
> >
> > > proc record {} {
> > >  puts stderr "recording"
> > >  global sink f0                               ;#  <<<<<<< changed line
> > >  set ns [Simulator instance]
> > >  set time 0.5
> > >  set bw0 [$sink(1) set bytes_]
> > >  set now [$ns now]
> > >  puts $f0 "$now [expr $bw0]"
> > >  $ns at [expr $now+$time] "record"
> > > }
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf
> > > Of Renata Vidal
> > > Sent: sexta-feira, 29 de Setembro de 2006 19:54
> > > To: ns-users
> > > Subject: [ns] LossMonitor - can't read, no such variable
> > >
> > >
> > > Why I can't set a variable like this: SinkCBR($i) ?
> > > Its got me crazy! If I set each variable like SinkCBR0, SinkCBR1 and
> > > so on, its be OK, but if I try SinkCBR($i) or SinkCBR$i I see the
> > > message "no such variable".
> > > Whats is wrong?
> > >
> > > ---------- Forwarded message ----------
> > > From: Renata Vidal <[EMAIL PROTECTED]>
> > > Date: Sep 28, 2006 2:47 PM
> > > Subject: LossMonitor - can't read, no such variable
> > > To: ns-users <[email protected]>
> > >
> > >
> > > Hi,
> > >
> > > I was trying to use the LossMonitor, but I see the message:
> > > ns: record: can't read "sink(1)": no such variable
> > >     while executing
> > > "$sink(1) set bytes_"
> > >     (procedure "record" line 12)
> > >     invoked from within "record"
> > >
> > > This a peace of my code, I don't know whats is wrong:
> > >
> > > (..)
> > > set sink($i) [new Agent/LossMonitor]
> > > $ns attach-agent $s($i) $tcp($i)
> > > $ns attach-agent $r($i) $sink($i)
> > > $ns connect $tcp($i) $sink($i)
> > > (..)
> > > proc record {} {
> > >  puts stderr "recording"
> > >  global sink(1) f0
> > >  set ns [Simulator instance]
> > >  set time 0.5
> > >  set bw0 [$sink(1) set bytes_]
> > >  set now [$ns now]
> > >  puts $f0 "$now [expr $bw0]"
> > >  $ns at [expr $now+$time] "record"
> > > }
> > >
> > > Any Clue?
> > >
> > > --
> > > Renata Vidal
> > > "Triste é o destino de quem tenta vencer as batalhas e ter sucesso nos
> > > ataques sem cultivar o espírito da iniciativa (A Arte da Guerra – SUN
> > > TSU – pg 102)"
> > >
> > >
> > > --
> > > Renata Vidal
> > > "Triste é o destino de quem tenta vencer as batalhas e ter sucesso nos
> > > ataques sem cultivar o espírito da iniciativa (A Arte da Guerra – SUN
> > > TSU – pg 102)"
> >
> >
> >
> 
> 
> --
> Renata Vidal
> "Triste é o destino de quem tenta vencer as batalhas e ter sucesso nos
> ataques sem cultivar o espírito da iniciativa (A Arte da Guerra – SUN
> TSU – pg 102)"


Reply via email to