Checking the Player's Inventory / Required Objects

I have been searching through the documentation, internet and this forum for information on checking the player’s inventory but haven’t yet found how this is done. My situation is this:

I’m not sure how to use darkness on a thing or container level, so I was going to check to see of the player has the lantern (in my case the only light source they could have on them), if they do have it describe what they see, otherwise tell them it is too dark etc.

So the correct way to do this would be able to get darkness working correctly (in this scenario, under a bed) - or - get the inventory check working so that I can fake it by checking their inventory for the lantern (this is def. not ideal since perhaps later they could be carrying any number of light sources.).

I hope I explained this clearly.

Thanks in advance!

The basic way to deal with light and darkness is to create light source objects by giving them brightness levels or using LightSource classes, and create dark areas by adjusting their brightness or using classes, such as DarkRoom.

Are you using TADS 3 and the Workbench? If so, just do a documentation search for ‘darkness’ and ‘brightness’ and you’ll see some code examples.

I am using TADS3 and have all the docs - but I wasn’t sure how to code a non-dark room with a dark thing in it - in my case a bed that is dark under it. Should I maybe use the rarely needed nested room so I can set that ‘room’ to dark and use it as the bed’s underside?

Thank you for your timely response and all your help!

Here’s one way to do it.

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

+ light: Flashlight 'flash flashlight/light' 'flashlight'
	brightnessOn = 5
;

bedroom: Room 'bedroom' 'bedroom'
	"Just another sparsely implemented bedroom. "
;

+ bed: Heavy, Surface 'bed' 'bed'
	"Your bed is filthy. Shame on you! "
	initSpecialDesc = "Your bed is here. "

	dobjFor(LookUnder) remapTo(LookUnder, underBed)
;

++ underBed: NameAsOther, Underside, Component
	targetObj = bed

	dobjFor(LookUnder) {
		preCond = [objSearchable]
	}
;

+++ widget: Hidden 'widget' 'widget'
	"You see nothing unusual about it. "
;

objSearchable: PreCondition
	verifyPreCondition(obj) {
		if (!gActor.isLocationBright())
			inaccessible(&tooDarkMsg);
	}
;

modify Actor
	isLocationBright() {
		if (sightlikeSenses.indexOf(sight) != nil
			&& location != nil
			&& location.brightness > 3
			&& location.transSensingOut(sight) == transparent)
			return true;
		return (getVisualAmbient() > 3);
	}
;

Looking under the bed remaps to looking under the bed’s Underside object, which has a custom precondition for the LookUnder action. This is essentially objVisible with some logic ripped out, and the call to gActor’s isLocationLit method replaced with one to isLocationBright.

This new method checks to see if the brightness is greater than 3 (the default brightness). That will only happen if the flashlight (with brightness 5) is turned on; otherwise the action will fail with the message “It’s too dark to do that.”

I was looking at this earlier and was surprised not to find a basic ‘this container is dark inside’ kind of property. Is that by design or was I missing something?

Yeah, I would think that this would be a common situation but perhaps not. I’ll try the solution outlined above tonight and let you know how it goes. Thanks again!

I don’t think you’re missing anything, but it’s not hard to leverage the sense-passing mechanics to roll your own.

[spoiler][code]
darkness: FillMedium
material : Material {
hearThru = transparent
seeThru = opaque
smellThru = transparent
touchThru = transparent
}
;

bag: Container ‘bag’ ‘bag’
lookInDesc = "The bag is filled with darkness. "
dobjFor(Examine) remapTo(LookIn, self)

// ought to be a method that changes the medium based on ambient light
fillMedium = darkness

;

  • Thing ‘gold coin’ ‘coin’
    "A gold coin. "
    ;
    [/code][/spoiler]

Perhaps there’s a more elegant way to do it; I don’t know as much as I’d like about sense-passing in adv3.

The under-bed remap technique above seems to work well, as long as I don’t give the ‘widget’ a specialDesc.