TADS 3 Adv3: How to remove old instances of a class?

If you’re just worried about “getting them out of the game”, then moving them into nil is sufficient. Otherwise if you know they’re not referenced any more, you can run the garbage collector. As for each one having a timer, you can do that with Daemons and Fuses. I created a ResettableEvent class to make your use case and many other use cases more streamlined. You could check it out Sharing a ResettableEvent class for TADS 3 or just have fun playing with Daemons and Fuses on your own…
I had several different flavors of disappearing objects, but the most basic type looked something like this:

  class EphemDmn: RDaemon
  	events { 
       if(!gPlayerChar.canSee(linkObj) 
               || !linkObj.ofKind(EphemeralDecoration) && ct >= 8) 
         linkObj.zap; 
    }	
;

where zap is a method that mainly moves into nil but also carries out any needed side effects depending on the class it’s used with, and linkObj is the animal meat instance that this Daemon is attached to. This particular Daemon will zap a certain class’s instances as soon as they go out of sight of the PC, or if the instance is EphemeralDecoration the instance will die eight turns after this daemon has been started (typically also provided the PC is out of sight, so we don’t have to explain mysterious disappearances from under our nose).
Somewhere there is defined an Ephemeral class that takes care of including an EphemDmn for each instance upon declaration or construction.
There’s more about usage in the link. Hope you can find some use for it, I sure did!

2 Likes