Wednesday, June 19, 2013

Error Setting Color to a node dynamically - Solution

In ns-2.35, while setting node colors dynamically I faced the following error.


 _o14 color blue: can't read "attr_(COLOR)": no such variable
    while executing
"eval list "n -t [format "%.15g" [$ns now]] -s $id_ -S COLOR -c $color -o $attr_(COLOR) -i $color -I $attr_(LCOLOR)""
    invoked from within
"if [$ns is-started] {

$ns puts-nam-config  [eval list "n -t [format "%.15g" [$ns now]] -s $id_ -S COLOR -c $color -o $attr_(COLOR) -i $color -I $attr..."
    (procedure "_o14" line 6)
    (Node color line 6)
    invoked from within
"_o14 color blue"

The above solution can be rectified by 

1. Set a default node color to all nodes at the time of creating nodes.

2. Make sure that node color need to be set with 

$ns at

Example

set ns [new Simulator]

for {set i 0} {$i < $val(nn)} {incr i} {
 set node_($i) [$ns node] 
 $node_($i) color blue   ;# setting up a default color
}

$ns at 0.1 "$node_(0) color green"
$ns at 0.1 "$node_(0) color red"



No comments: