Clear Agents

Ken Webb 2010-11-17T00:00:00Z

A JavaScript script to clear all agents from the simulation.

<script implName="lang:javascript:inline:"><![CDATA[
Clear Agents
Clear all agents from the simulation.
An agent is any child of a HabitatCell, for example:
 - a Cat, Human or other active object
 - a House or other more passive object
This JavaScript script does two things:
 1. dequeue all objects from the Beasts Q
 2. remove all objects in the tree that are children or descendants of a HabitatCell node
You can run this script on the Bestiary node, or any node in the tree that's a descendant of Bestiary.

var contextNode = contextNodeKey;
function clearBeastQ(qNode) {
 item = qNode.dequeue();
 while (item) {
   item = qNode.dequeue();

function clearAgents(node) {
 myXhcName = node.getXhcName();
 if (myXhcName == 'Beasts') {
 else if (myXhcName == 'HabitatCell') {
   // remove all children of the HabitatCell
   myChild = node.getFirstChild();
   while (myChild) {
     myChildTemp = myChild.getNextSibling();
     myChild = myChildTemp; // get sibling of removed node, if any
 node = node.getFirstChild();
 while (node) {
   node = node.getNextSibling();

contextNode = contextNode.getRootNode();

return to main page