Maree的头脑风暴
注册日期:
2016-10-29 04:58:41
上次登录:
2016-10-29 04:58:41
邮件地址:
1923201614@qq.com
  
Maree的更多标签
swarm for Java 中练习行为列表时出现的问题
2016-10-29 05:33:12  swarm for Java 

大家好,swarm运行中出现了一个问题,谁能帮我解决一下 Microsoft Windows XP [版本 5.1.2600]

(C) 版权所有 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Administrator>d:
 
D:\>cd 练习
D:\练习\ActionGroupDemo>javac *.java
 
D:\练习\ActionGroupDemo>java ActionGroupDemo
(Tcl -eval:) wrong # args: should be "source fileName"
    while executing
"source C:\Program Files\Swarm-2.2-java/lib/tcl8.4//word.tcl"
while evaluating: source C:\Program Files\Swarm-2.2-java/lib/tcl8.4//word.tcl
*** event raised for error: InvalidOperation
*** function: _i_CSwarmProcess__activateIn_(), file: /src/swarm/src/activity/Swa
rmProcess.m, line: 208
> Swarm has already been activated.  A swarm cannot be activated more than
> once.
*** execution terminating due to error
/src/swarm/src/defobj/Symbol.m:187 -[Error(c) _raiseEvent:]
 
D:\练习\ActionGroupDemo>
 
代码如下:
import swarm.objectbase.Swarm;
import swarm.objectbase.SwarmImpl;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.activity.ActionGroupImpl;
import swarm.collections.ListImpl;
import swarm.collections.ListImpl;
import swarm.defobj.Zone;
import swarm.Globals;
import swarm.Selector;
class Agent{
char id;
Agent (char id){
this.id=id;
 
}
 
public void agentStep(){
System.out.println(id + ":" + Globals.env.getCurrentTime());
 
}
}
 
public class ActionGroupDemo extends SwarmImpl{
 
ScheduleImpl schedule;
ActionGroupImpl actionGroup;
ListImpl list;
char Id='a';
ActionGroupDemo(Zone aZone){
super (aZone);
list=new ListImpl(aZone);
swarmStep();
actionGroup=new ActionGroupImpl(aZone);
schedule=new ScheduleImpl(aZone);
try{
Selector agentSel=new Selector(Agent.class,"agentStep",false);
Selector swarmSel=new Selector(ActionGroupDemo.class,"swarmStep",false);
actionGroup.createActionForEach$message(list,agentSel);
actionGroup.createActionTo$message(this,swarmSel);
schedule.at$createAction(0,actionGroup);
schedule.at$createAction(1,actionGroup);
schedule.at$createAction(2,actionGroup);
}catch (Exception e){
 
e.printStackTrace(System.err);
System.exit(1);
System.out.println("recaught: "+e);
 
}
 
}
 
public void swarmStep(){
list.addLast(new Agent(Id));
Id++;
}
 
public Activity activateIn(Swarm context){
 
super.activateIn(context);
super.activateIn(this);
return getActivity();
}
 
public static void main(String[] args){
Globals.env.initSwarm("ActionGroupDemo","2.1","r@r",args);
Swarm swarm=new ActionGroupDemo(Globals.env.globalZone);
swarm.buildObjects();
swarm.buildActions();
swarm.activateIn(null).run();
}
}

 

登录后才可以评论,马上登录