A TADS3 module providing utilities for working with sense tables

Building on some stuff I originally wrote over a year ago, here’s a simple module for working with sense tables: senseGrep github repo.

This grew out of some logic for scene-like stuff I’ve been working on. Basically in NPC scripting I was constantly running into situations where I want an easy way to script things like “does Alice see any books?”

The module provides a generic function senseGrep() that by default returns all the objects currently visible to gActor. Usage is:

      // Returns all the objects visible by gActor.
      local l = senseGrep();

This is equivalent to:

      local l = senseGrep(sight, gActor, function(o, s) { return(true); });

…where the first arg is the sense to use (sight, sound, smell, or touch, defaulting to sight), the second is the actor (defaulting to gActor), and the last arg is an optional filter function (default is to return all objects detectable via the given sense).

There’s also a senseGrepFilter() function that takes an include list and an exclude list as its third and fourth arguments:

      // Returns all the objects visible by Bob, not counting himself
      // and any Fixture objects.
      local l = senseGrepFilter(sight, bob, nil, [ bob, Fixture ]);

      // Returns all the Actors visible to the player, not counting themself.
      local l = senseGrepFilter(sight, me, Actor, me);

In addition, there are a couple filter generator functions designed to make it easier to match nouns, adjectives, or both on objects. The functions are wordFilter(), nounFilter(), and adjectiveFilter() and each takes a single string literal as its argument:

      // Returns all the books visible to the player.
      local l = senseGrep(sight, me, nounFilter('book'));

      // Returns all the red objects visible to the player.
      local l = senseGrep(sight, me, adjectiveFilter('red'));

Basically just a bunch of reasonably straightforward utility methods that I found myself needing frequently…so here’s another module.

8 Likes