Help

JS-VISIT

For immortals Also: JAVASCRIPT-VISIT

Many objects support methods which start with "visit". For example the "visitAttackers()" method on characters. These methods all work in a similar way and provide a mechanism for operating over groups of characters or objects. For example:

function blind( to ) {
  self.cast( 'blind', 'args', to );
}

function heal10( to ) {
  to.msg( "The song's wonderous melody rejuvenates you." );
  to.hit += 10;
}

self.visitAttackers( blind );
self.visitGroup( heal10 );

The effect of the above JavaScript would be to cast the blind spell on anyone who is attacking the mobile that the above script is attached to. In addition, the mobile would also cast a light healing song on everyone who is grouped with the mobile. In addition, if "array1" consisted of a JavaScript Array containing characters, then the following could be used to heal every character in the array by 10 hit points:

array1.visit( heal10 );

You can also pass an array to the visit() functions as well. In this case rather than call a function for each visited element, each visited element will be added to the array instead. For example, the following fills up myArray with a copy of all the attackers.

var myArray = new Array();
self.visitAttackers( myArray );

The various visit functions also take an optional second argument which is a predicate function. This function should take a single object and then return true or false if the object passes the predicate. For example, the following would apply the blind() function to all of the attackers who have less than 50 hit points.

function weaklings( to ) {
  return to.hit < 50;
}
self.visitAttackers( blind, weaklings );

If a visit function returns false, then the mud will stop visiting objects. For example, if you only wanted to damage the first three characters in a room, you could do it with:

function dam( o ) {
  damage( 'fire', 10, o );
  --count;
}
dam.count = 3; visitChars( dam );