T3: Searching in the Dark

I’m trying to implement a tiny puzzle. The player does an action, and suddenly it’s dark. Unless the player has done something perverse, the PC is wearing his backpack, and there’s a flashlight in the backpack. But as the flashlight has not been needed heretofore, it’s entirely possible that the player doesn’t know or doesn’t remember that the flashlight is there.

So I need the player to be able to search the backpack (by feel) even though it’s dark.

‘search backpack’ by default gives “It’s too dark to do that.”

So I give the backpack brightness = 1 and the flashlight brightnessOff = 1. Now I get, “Your backpack contains a flashlight.” That makes the game playable, but what I want is something like this:

“Groping in your backpack, you feel the flashlight.”

The output message is coming from a lister, I’m sure … but which lister? That’s where I’m stumped. I don’t even know how to find the library code that implements the lister.

Also, while I’m on the subject – I can never remember whether the library defines dobjFor(LookIn) asDobjFor(Search) or the other way around, and I couldn’t track down that information either. It might make a difference, as you can produce an infinite loop by routing each of them to the other.

Actors have an inventoryLister property; you can override it to use your own implementation. In this case it doesn’t sound like it has to be very fancy.

me: Actor
	location = bedroom
	inventoryLister = getVisualAmbient() < 3
		? darkInventoryLister
		: actorInventoryLister;
;

darkInventoryLister: actorInventoryLister
	showCombinedInventoryList(parent, carrying, wearing) {
		"Wow it's really dark in here. ";
	}
;

bedroom: Room 'bedroom' 'bedroom'
	"Just another bedroom. "
	west = bathroom
;

bathroom: DarkRoom 'bathroom' 'bathroom'
	"Don't turn on the light! "
	east = bedroom
;

I’m a bit wary of that getVisualAmbient() call - I’ve had it blow up on me in the past - but it seems to work OK here.

It defines dobjFor(Search) asDobjFor(LookIn).

Hmm … thanks for trying, but it’s not quite working the way I have in mind. I added the darkInventoryLister as you suggested, and now I get the following output:

What I want (in the dark) is this:

The point being, if you’re wearing or carrying something, you hardly need visual sensing to know what it is. That, and the “groping in the pack, your fingers locate” prefix, which should then go on to list everything in the pack, even though it’s dark, because you can touch it and figure out what it is.

Sorry, for some reason I thought you wanted the inventory output altered.

You can apply similar logic to the lookInLister property of your backpack. I’ll work up an example when I get back home.

OK, here goes.

me: Actor
	vocabWords = 'self'
	location = bedroom
;

+ backpack: OpenableContainer 'pack/backpack' 'backpack'
	// make sure backpack can be examined in the dark
	brightness = 1

	// use a different contents lister in the dark
	lookInLister = gPlayerChar.getVisualAmbient() < 3
		? darkThingLookInLister
		: thingLookInLister

	// suppress contents listing when opened
	dobjFor(Open) {
		action() {
			makeOpen(true);
			defaultReport(&okayOpenMsg);
		}
	}

	// put everything inside the backpack in scope
	getExtraScopeItems(actor) {
		return isOpen ? contents : [];
	}
;

++ flashlight: Flashlight 'flashlight' 'flashlight'
	// make sure player can handle the flashlight
	brightnessOff = 1
;

++ paperweight: Thing 'paperweight' 'paperweight';

darkThingLookInLister: thingLookInLister
	// replace default prefix
	showListPrefixWide(itemCount, pov, parent) {
		"\^Groping around in the pack, your fingers locate ";
	}

	// do not filter the contents for visibility
	getFilteredList(lst, infoTab) {
		return lst;
	}
;

bedroom: Room 'bedroom' 'bedroom'
	"Just another bedroom. "
	west = bathroom
;

bathroom: DarkRoom 'bathroom' 'bathroom'
	"Don't turn on the light! "
	east = bedroom
;

Thanks! That seems to take care of it nicely. I’m going to have to re-read the Lister article in the Tech Manual…