Contents of containers in containers

Completely new to Inform. I can’t seem to find a way to create a list of ALL the visible items in a container. The container could have containers in it that have items in them…
Example: a storage bench has a hand bag which has a coin purse with a coin in it. I am trying to get a list that would be:
hand bag
coin purse
coin

if anything is “closed”, then the list wouldn’t show the nested items.

Displaying a list is introduced in chapter 5.5. But the special options are listed at the end of 11.14. In particular, you want

list the contents of the foo, including contents.

Maybe also “giving inventory information” if you want to include tags like “(worn)”.

1 Like

i’ve tried looking at that from the examples:

let LT be the list of things in the chest including contents;

but this balks (with or without the comma).

Welcome to the forum!

While Inform’s natural language syntax can make for code that’s easy to read, it’s not always as easy to write, because you have to come up with the exact right natural-sounding thing that the compiler will actually accept, while an infinite number of other things both make sense as English and are close to what Inform needs but won’t work.

Below are different approaches to saying aloud the contents of something:

Lab is a room.

Box is an open container in the Lab. Matchbox is an open openable container in the box. Matchstick is in the matchbox.

when play begins:
  say "list the contents of the box, including contents, as a sentence: [line break]";
  list the contents of the box, including contents, as a sentence;
  say line break;
  say "say 'a list of things in the box including contents'[line break]";
  say "[a list of things in the box including contents][line break]";
  say "repeating through list of things enclosed by the box:[line break]";
  repeat with item running through the list of things enclosed by the box begin;
    say "[item].";
  end repeat;
  say "repeating through things enclosed by the box (no list):[line break]";
  repeat with item running through things enclosed by the box begin;
    say "[item].";
  end repeat;

list the contents of the box, including contents, as a sentence is a phrase. It must be used within a rule or another phrase. It can’t be used inside brackets in a say statement.

a list of <description of objects> including contents is a say-phrase. It can only be used in a say statement. And it’s inflexible on the article: you can’t use “the” or omit the “a”.

list of <description of objects> is a phrase returning a value – the list of objects you can then repeat through. But you don’t actually need to build a list, because repeat can take a description of objects directly as the last example shows. Save a list of... for when you want to assign it to a variable for some other sort of processing.

So including contents can only be used in those two particular cases, the list the contents phrase that Andrew mentioned, or that say phrase. Or you can say let LT be the list of things in the chest and you’ll get just the things directly contained without getting their contents.

enclosed will return all things contained and indirectly contained… but possibly other things, if you have things that are parts of things, or a person within the container who’s wearing or carrying things, or a supporter within the container that’s supporting things. If your game isn’t going to have any of those things, enclosed is good enough, but if you’re doing something complicated, you’ll need something more complicated.

4 Likes

great - thank you.
I am playing around and trying to understand how to get my ideas into the language, as needed.
using the example i got it to working as expected.

repeat with toy running through things enclosed by The Toy Chest:
	if toy is not inside a closed container:
		let toy_name be the printed name of toy;
		if toy_name is a Treasure listed in the Table of Point Values:
			increase the score by the Points corresponding to a Treasure of toy_name in the Table of Point Values;

if the matchbox is closed, then the matchstick isn’t recorded.

Thank you