For Whom the Bell Trolls

This demonstration covers several issues groups have raised: how to handle the Library verb "Attack"; how to add new synonyms to an existing verb; and how to kill off a Non-Player Character.

Consider the following NPC:

Object troll "Troll" firstRoom
  with 	description "An entirely ordinary troll from Central Spellcasting.",
  	name 'troll',
  	numHits 0,
  	alive true,
  	life [;
  	  Attack:
  	    if(self.alive == false)
  	    {
  	      print_ret "He's dead, Jim.";
  	    }
  	    self.numHits ++;
  	    print "You smite the troll ruthlessly with your fearsome handtowel.^";
  	    switch(self.numHits)
  	    {
  	      1:
  	        "The troll says 'Mm.'";
  	      2:
  	        "The troll says 'Ow,' and deals you a staggering blow.";
  	      3:
  	        print "The troll topples to the ground, more less dead.^";
  	        self.alive = false;
  	        return true;
  	    } 
  	],
  has	animate;

First, notice that the Troll responds when attacked. That is, its Life property (acting in the same way as a Before) intercepts the word "attack" and its predefined synonyms such as "hit," "strike," and "thump."

We introduce the variable numHits to give this Troll a certain amount of resiliency. You have to smite the Troll three times to achieve a kill. You may of course design a different logic if you prefer.

On the third attack, the troll expires. Originally, thinking myself clever, I wrote:

give self ~animate;

instead of setting that custom variable alive to false. I was perturbed to find, after doing this, that further attacks on the Troll were met with the standard can't-attack-this response, "Violence is not the answer here." This response is triggered whenever the Player attacks an inanimate object, which the Troll becomes once it is given the state not-animate. We need to keep the Troll animate, but not living. Calling George Romero.

The custom variable allows us to do this, so the Player can continue to flog a dead Troll until s/he collapses in futility. If the Troll has been struck more than three times, we say "He's dead, Jim," and play continues.

Finally, a word about the verb Attack. While it has several useful synonyms in the Library, it could use a few more. So we include the following at the end of our .inf file:

Verb 'smite' 'strike' 'whack' 'crush' 'beat' 'kick' * noun -> Attack;

Technically, this line creates a new verb called Smite, but since that word and its synonyms call the Attack routine from the Library, it has the effect of extending the original verb. You can do this with any verb; just be prepared for error messages if you include a word that is already a synonym in the Library.

The complete .inf file for this example, attack_1.inf, is available in COSC320/1114 within the common directory on student-iat.



University of Baltimore Logo

Last updated: 01/02/07 18:35:45
Copyright © 2006 School of Information Arts and Technologies