Starting an Environment

Some environments start automatically when loaded, while others must be started by an agent. To start an environment one of the connected agents must execute one of the following two EIS API actions: startEnv()or startEnv(envId). We illustrate this by extending the example Tower program above:

  package examples;
  
  agent Tower {
      module EISAPI eis;
      
      initial !init();
      
      rule +!init() {
          eis.launch("tower", "towerenv.jar");
          eis.join("tower");
          eis.link("gripper");
          eis.startEnv();
      }
  }

Sometimes it is not clear whether the environment needs to be started. In this case, the current state of the environment can be identified by using one of the following EIS API terms: getState() or getState(envId). Normally, an environment will be created in a “paused” state. Once the environment has been started, it moves into a “running” state. The following code uses one of these terms to provide a better general solution to starting the environment:

  package examples;
  
  agent Tower {
      module EISAPI eis;
      
      initial !init();
      
      rule +!init() {
          eis.launch("tower", "towerenv.jar");
          eis.join("tower");
          eis.link("gripper");
          if (eis.getState() == "paused") eis.startEnv();
      }
  }