I am writing code for a simple simulation. We have 10 nodes and one sink node.
I want to run the simulation for 5 times.
The only thing I know so far is that I need to write set val(repeatTimes) 5
, but I don't know how to use it in the simulation. Also, I add two lines of code as follow in the corresponding mac-simple.cc file in order to receive the repeat time from ns2. Then I compile the .cc file and run the simulation. However, when I run the .tcl file it shows me an error that it cannot find the repeatTimes variable.
Here are the two lines of code that I add under the function Mac():
tcl.evalf("Mac/Simple set repeatTimes");
bind("repeatTimes", &repeatTimes);
Do you the solution to this problem? If you don't know the solution, can you please guide me towards a forum/website where I can look for the solution?
Thanks in advance
Is the
bind
in your constructor for the class of theMac/MncPrj
object? (That's where it needs to be.) If so, it needs to be before thetcl.evalf
call because it defines the variable from the perspective of OTcl; the code to read it won't work (and will generate a Tcl error — an exception in the Tcl level — if you try to do it) until after the binding has been done.Once you've done the binding, you can read the variable from the Tcl script side with:
and write it with:
You should avoid keeping the value in a Tcl array; that'll be a non-live copy and will confuse you. (Unless you get much deeper into the magic of
trace add variable
, and that will definitely confuse you. It confuses me sometimes!)