TADS 3 Lite - isIn(obj) question

I’m trying to set up a situation where if four specific objects are placed in a container, a thing happens. I’ve directed each object to include a call to the a method in the container to see if all four objects are inside, but it hasn’t been triggering.

To test it out I added messages to confirm that the method was being accessed (it was) and also to see what the tested object’s location was.

++ someObject: Thing 'vocab etc' dobjFor (PutIn) { action() { inherited; if (gIobj != theContainer) return; "A description of putting the object in the container. "; theContainer.importantCheck(); } }

Variations of this in all four objects. And then the container’s method:

		"Making the check now. ";
		if (someObject.isIn(theContainer) && someOtherObject.isIn(theContainer) && yetAnotherObject.isIn(theContainer) && theLastObject.isIn(theContainer))
			"All four objects are in the container. ";

I also added code into someObject’s desc to report its location’s name when examined.

Examined in my inventory: You.
Reported when placing it in the container and calling importantCheck: you.
Examined after placing it: the container.

So for some reason when importantCheck is called, it still thinks someObject is in me, despite having already (presumably) put it into theContainer. Any way around this, or am I missing an easier way to go about this?

I’m not sure what’s going wrong in your code, but I can tell you that you don’t need to write an importantCheck() routine. The library provides notifyInsert (obj, newCont). This is called just before the object is inserted into the container, but after all of the other checking has been done, so the action will definitely proceed (unless, or so I seem to recall, notifyInsert returns nil). See p. 69 of “Learning T3” for details.

…and here’s the answer. A dip into the Library Reference Manual indicates that the actual movement of an object into a container is handled not in dobjFor(PutIn) of the object being moved, but in iobjFor(PutIn) of the container. As a result, your call to inherited does nothing.

You can put your importantCheck code in the action() block for iobjFor(PutIn) of the container, following a call to inherited, and it should work. Or you can use notifyInsert, as I suggested before.

I’ll use notifyInsert first. Thanks!

Postscript: notifyInsert didn’t work (it happens before the object is moved) but putting the code in the iobj’s iobjFor(PutIn) did the trick.

My guess is, you were still trying to test whether the object was in the container. Instead, in notifyInsert(obj, newCont) you should test whether the other stuff is already in the container, using the current value of obj in a switch statement. But yeah, I think the code would be less messy if you put it in the iobjFor(PutIn) action block.