//***** 2008.03.25 update *****

原來要從 TCL 丟值進 agent 中,並沒想像中那麼難(知道怎麼傳之後,才這樣說= =,之前心底還在叫:難啊!)

=====newagent.h=====

class NewAgent : public Agent {
public:
NewAgent(); //建構子
int command(int argc, onst char*const* argv);
private:
int var1; //要傳入的變數一,型態為 int
double var2; //要傳入的變數二,型態為 double
};

=====newagent.cc=====

NewAgent::NewAgent() : Agent(PT_DIFF)
{
//將 TCL 中的 var1_otcl 變數對應到 agent 中的 variable var1
bind("var1_otcl", &var1); //在建構子中加入,希望在agent 產生同時,就將值傳入 var1 的型態為 int
bind("var2_otcl", &var2); //在建構子中加入,希望在agent 產生同時,就將值傳入 var2 的型態為 double
}

最後在 TCL 中加入設定,就可以順利將值丟入 agent 中啦!

但在 TCL 中,要使用傳入值丟入到 agent 中,雖可以執行,但卻有警告訊息,看起來很礙眼 ~"~

warning: no class variable Agent/NewAgent::var1_otcl2_

see tcl-object.tcl in tclcl for info about this warning.

一般看到的寫法似下方的方式,但就會產生上方兩句(重覆很多遍)的訊息

set newagent [new Agent/NewAgent ];

 newagent set var1_otcl_ 10

 newagent set var2_otcl 0.95

Google 一下,看到將傳入方式改為以下方式,訊息就不會亂飆出來了…

set newagent [new Agent/NewAgent ];

 newagent set var1_otcl_ 2

 Agent/NewAgent set var1_otcl_ 10

 newagent set var2_otcl 3.14

 Agent/NewAgent set var2_otcl 0.95

.

============2008.03.25 update 將 agent 掛至 node 的作法=====================

……..

…………..
for { set i 0 } { $i < $val(nn) } { incr i } {

#1.先設定傳入值的變數,待 Agent attach 到 node 中使用

Agent/NewAgent set var1_otcl_ 10

Agent/NewAgent set var2_otcl 0.95

#2.將 agent attach 到 node上使用

set flooding_($i) [new Agent/NewAgent] ;#將各個 node 加上 agent ,並將變數傳入

...... ...
}

後記:

先前發生的狀況為:先 attach 第 0 個 node 有 agent 然後再宣告變數,這樣導致第 0 個node(第1個node之後就都有收到)會沒接收到變數而產生警告, 而輸出以下訊息

warning: no class variable Agent/NewAgent::var1_otcl2_

see tcl-object.tcl in tclcl for info about this warning.

※這是因為先 attach 再宣告變數產生的問題,導致最初的一個會收到空值

先宣告好變數,再 attach 就不會有這樣的問題了 ~~

相關文章:

小娟 – 孤單聖誕 Christmas Alone(番外篇)
小娟 – 孤單聖誕 Christmas Alone(番外篇)

2010跨年煙火-台北101
2010跨年煙火-台北101

QQ@N.C.F
QQ@N.C.F

揮之不去
揮之不去

天堂之鑰 – 基國派老教堂
天堂之鑰 – 基國派老教堂

[隨拍]燈
[隨拍]燈

Tags: ,