[TADS3] counting rooms visited

I have a coding problem:

basically, I need that the character (not the player) noticing, after visiting the first four or so locations, that something is off (a clue to the player) But I don’t figure how to count the number of rooms visited so far (perhaps the solution is hidden in the mare magnum of methods, properties, classes &c. ?)

Best regards from Italy,
dott. Piergiorgio.

Not tested, but shouldn’t afterTravel work? Like:

Bob: Actor 

visitedRoomTrail = []
afterTravel(traveler, connector) {

  inherited (traveler, connector);
  visitedRoomTrail += location;

    "Bob makes a statement"


In adv3/travel.t, the BasicLocation class has this method:

 *   Receive notification that a traveler is arriving.  This is a
 *   convenience method that rooms can override to carry out side
 *   effects of arrival.  This is called just before the room's
 *   arrival message (usually the location description) is displayed,
 *   so the method can make any adjustments to the room's status or
 *   contents needed for the arrival.  By default, we do nothing.
enteringRoom(traveler) { }

You can create a special class for the locations that partake in room counting that inherits from one of the BasicLocation subclasses (like Room). Override enteringRoom(traveler) in that class to increase a global counter if traveler is the player character, and check if it’s >= 4 and if yes, run the clue code. Make all locations that should be affected by this be objects of that class.

Thanks to both !
Albeit Tomas’s idea is good, RealNC’s one looks better because follows TADS’s philosophy since 2.0, namely using modify/replace, hence my flagging RealNC’s reply as solution.

I’m sure that using appropriately enteringRoom and hasSeen/setHasSeen (the latter because I prefer avoid counting player’s backtracking; the obvious brute-force approach (checking and counting the trues of [room].hasSeen of the dozen or score of locations nearest the start location) is definitively NOT good coding…

Best regards from Italy,
dott. Piergiorgio.

Note that there’s no modify nor replace here. Just inheritance and overriding of inherited methods:

class MagicRoom: Room
        inherited(traveler); // just good practice for future-proofing
        if (traveler != gPlayerChar) {
        if (travel_counter > 3) {
            // show clue

Locations affected by this should them be of class MagicRoom.

Thanks. After adding an AND check if is first time visited, is perfect for what I envision. On top of it, allows adding an AGT feature I sorely miss (the rooms discovered count in the score/quit)

Best regards from Italy,
dott. Piergiorgio.