New to Inform: synonyms and conditionals

Hi all. I’m new to this forum, and new to Inform.

By way of introduction, I began playing text adventures as a kid around '80 on a VT 100 terminal calling into a mini computer. I was also a big Infocom fan, and had a number of their games on my Apple ][. I have recently gotten my 10-year old daughter interested in Infocom games, and then she was delighted to find Colossal Cave on her Kano computer. We decided to look into learning to write IF, and located Inform, which we have started using. Our first attempt is a very simple set of rooms mirroring our home, with a couple of easy puzzles intended to help us learn how to do certain things. With regard to this, I have a couple of questions. We spent a fair bit of time yesterday scanning the documentation, googling, and trying different things to sort these two (simple, I’m sure) issues out.

We have a bookshelf which is a container. You seem to need to use the preposition “in” to put something into a container, but no one says “Put the book in the bookshelf.” They always say “on”. I tried variations on this:

Understand “put [something] on bookshelf” as putting it in the bookshelf.

…to no avail. What is the correct approach here?

My second item is directly related. This errors when we try doing it, and I’m not sure where we have gone wrong:

After putting the storybook in the bookshelf:
say “The house feels tidier already.”;
remove the storybook from play;
increase the score by 10;

The error we get is:

Problem. You wrote ‘After putting the storybook in the bookshelf’ , which seems to introduce a rule taking effect only if the action is ‘putting the storybook in the bookshelf’. But that did not make sense as a description of an action. I am unable to place this rule into any rulebook.

The above is modeled on a nearly identical code block that works without a hiccup:

After giving the scraps to Nighty:
say “The gerbil begins to munch hungrily.”;
remove the scraps from play;
increase the score by 10;

Thank you for any help you may be able to offer.

The main problem is that you need to get exactly the right name for the action you’re talking about. While many actions can be invoked by many different commands (e.g. TAKE BOOK, GET BOOK, PICK BOOK UP), there’s only one way to refer to a given action in the source code (in that case it’s “taking the book”).

In this case the name of the action you perform when you type “PUT STORYBOOK IN BOOKSHELF” is the action of inserting the storybook into the bookshelf. There are a couple of ways to figure this out. One is to start the program, type “actions” at the command prompt, and then try your command. That will tell you what action the program is trying:

Another way is to go the the Index and look at the Actions Index and the Commands tile. Then look up the command form you are looking for; you will find this as one of the things under “put”:

Now, for your first thing there’s another couple issues. The first is that your Understand line is slightly misformulated. You can’t tell Inform to Understand anything as putting it into the bookshelf; you can only say what action is intended, you can’t specify the second noun in the Understand line as well. This would compile:

Understand "put [something] on [bookshelf]" as inserting it into.

However, that won’t actually accomplish anything, because there’s still an Understand line that tells Inform to understand PUT STORYBOOK ON BOOKSHELF as putting the storybook on the bookshelf, and that takes precedence. The simplest way to do this is to allow the command to be understood as putting the storybook on the bookshelf and redirect the behavior for that. So:

Instead of putting something on the bookshelf: try inserting the noun into the bookshelf.

This lets PUT STORYBOOK ON BOOKSHELF be understood the original way, as the action of putting the storybook on the bookshelf; but it cuts off the processing of the action before the rule that produces a failure message, and carries out the action of inserting the storybook into the bookshelf instead (what you’d get for PUT STORYBOOK IN BOOKSHELF).

(And welcome to the forum! A tip: it’s very helpful if you enclose your code snippets in code tags. Just hit the “Code” button that appears above the box where you type your comments–after the “Quote” button–and type or paste your code in between the resulting tags.)

Another solution is to make your bookcase an open, unopenable container, make it fixed in place unless it’s small enough to move, and then create a supporter called “bookshelves” which is part of the bookcase, with the synonym “shelf/shelves” and “book shelf/shelves”. You could then redirect inserting a book into the bookcase to putting the noun on the bookshelves.

[rant=Example][code]“Shelves”

Library is a room.

A bookcase is an open, unopenable, fixed in place container in Library. “A handsome bookcase is the main feature of the room[if something is on bookshelves]. The only thing on the shelf that doesn’t belong is [a list of things on bookshelves][end if].” Understand “handsome/case” and “book case” as bookcase.

Some bookshelves are a supporter. They are part of bookcase. Understand “shelf/shelves” and “book shelf/shelves” as bookshelves.

Instead of examining bookcase:
try examining bookshelves instead.

A book is a kind of thing. Understand “book” as a book.

WP is a book in library. “Someone has left your copy of [italic type]War and Peace[roman type] on the floor.”. The description is “You don’t have time to read it all now.” The printed name of WP is “a book called [italic type]War and Peace[roman type]”. Understand “war/peace” and “war and peace” as WP.

Creating Interactive Fiction is a book in Library. “Another book lies on the floor in the corner, who must have been in here last?”. The description is “[italic type]Creating Interactive Fiction with Inform 7[roman type] by Aaron Reed. You must get to this next.”. The printed name is “a book called [italic type]Creating Interactive Fiction with Inform 7[roman type] by Aaron Reed”. Understand “by Aaron/Reed” and “with Inform 7” as Creating Interactive Fiction.

A Wishbringer stone is in Library. The description is “It glows purple in the dark.”

Check inserting a something into bookcase:
try putting the noun on bookshelves instead.

Rule for writing a paragraph about bookcase:
omit contents in listing.

Rule for printing the name of bookcase:
Omit contents in listing.

After putting a book on bookshelves:
remove the noun from play;
say “Ah, that’s gone a long way towards tidying up the library!”

Test me with “take all/put all in bookcase/l/x bookcase”[/code]

Library
A handsome bookcase is the main feature of the room.

Someone has left your copy of War and Peace on the floor.

Another book lies on the floor in the corner, who must have been in here last?

You can also see a Wishbringer stone here.

test me
(Testing.)

[1] take all
a book called War and Peace: Taken.
a book called Creating Interactive Fiction with Inform 7 by Aaron Reed: Taken.
Wishbringer stone: Taken.

[2] put all in bookcase
Wishbringer stone: Done.
a book called Creating Interactive Fiction with Inform 7 by Aaron Reed: Ah, that’s gone a long way towards tidying up the library!
a book called War and Peace: Ah, that’s gone a long way towards tidying up the library!

[3] l
Library
A handsome bookcase is the main feature of the room. The only thing on the shelf that doesn’t belong is a Wishbringer stone.

[4] x bookcase
On the bookshelves is a Wishbringer stone.[/rant]

Thank you very much to both of you for your responses. I have done some programming over the years, but am completely new to this, so forgive me if I clumsily misunderstand things.

I first tried HanonO’s approach. Here are the relevant lines:

The Schoolroom is a room. "This is a squarish room which looks like it is currently being used for school. It has a piano, a couch, and several bookshelves along the west wall." The Schoolroom is south of The Hallway.

A book is a kind of thing. Understand "book" as a book.

	A paperback novel is a book in Schoolroom. The description of the paperback novel is "It looks like some kind of mystery."

A bookcase is an open, unopenable, fixed in place container in Schoolroom. "Against the one wall is a bookshelf." Understand "shelf" and "book shelf" as bookcase.
	
A bookshelf is a supporter. It is part of bookcase. Understand "shelf/shelves" and "book shelf/shelves" as bookshelf.

	Check inserting a something into bookcase:
		try putting the noun on bookshelf instead.
		
	After putting a book on the bookshelf:
		remove the noun from play;
		increase the score by 10;
		say "Ah, that's gone a long way towards tidying up the house!"

If I understand this correctly, we’re using the combined container and supporter so I can use the check/try lines to redirect action and put the book on the bookshelf since it’s a supporter. This seems to be a clever bit of sleight-of-hand. Am I understanding it correctly? Question: Why is the bookcase necessary, if I can just put something on the bookshelf? I tried it without the bookcase, and it doesn’t seem to recognize the supporter anymore?

I altered my bookcase description to say “bookshelf” so that the player would never see “bookcase” anywhere. Now though, while “put book on bookshelf” works, if they type “put book in bookshelf” gets the response “That can’t contain things.” This technically does what I asked for, but is there away to conflate put on/put in? It may not be as important here, but could easily come up elsewhere.

All things being equal though, matt w’s approach seems much less involved. Is there a specific advantage to doing it the other way? The one downside I see is the response says “into”:

put novel on bookshelf
You put the paperback novel into the bookshelf

I’m assuming that can be overridden, but am too tired to look for how at the moment.

It’s nice to understand different approaches, since I’m just starting to learn how the language wants to work. Thank you both again.

(code for matt w’s method:)

The Schoolroom is a room. "This is a squarish room which looks like it is currently being used for school. It has a piano, a couch, and several bookshelves along the west wall." The Schoolroom is south of The Hallway.

A book is a kind of thing. Understand "book" as a book.

	A paperback novel is a book in Schoolroom. The description of the paperback novel is "It looks like some kind of mystery."

	A bookshelf is an open, unopenable, fixed in place container in Schoolroom. "Against the one wall is a bookshelf." Understand "shelf" and "book shelf" as bookshelf.

		Instead of putting something on the bookshelf: try inserting the noun into the bookshelf.
		
	After putting a book on the bookshelf:
		remove the noun from play;
		increase the score by 10;
		say "Ah, that's gone a long way towards tidying up the house!"

You should be able to manage without the bookcase. Did you remember to place the bookshelves in the Schoolroom?

The bookshelves are a fixed in place supporter in Schoolroom.

And this would be my solution. Since you want the books to be “on” rather than “in” the bookshelf, make it a supporter rather than a container.

The cleanest solution yet. I like the way this works.

Am I missing advantages that the other two have?

I just tried it. I am making things over-complicated because I am used to using CHECK rules which require that the action be possible to redirect it… Having a dummy container there allows you to check inserting into a supporter, which can’t also be a container, so…

A bookshelf is a supporter in Library.

Check inserting something into bookshelf: try putting the noun on bookshelf instead.

Does not work because INSERTING is not possible with a supporter, but

Instead of inserting something into bookshelf: try putting the noun on bookshelf.

interrupts before a check, so you can likely omit the dummy container.

I usually urge people to avoid INSTEAD rules when possible in favor of CHECK…INSTEAD, but this is an ideal case where you’re not doing a lot of complicated things in the rule.

This to me is one of the benefits of I7 that drives programmers crazy; you can accomplish the same effect in multiple ways and there isn’t necessarily a “wrong” one.

If you have conflicting check rules, you can add a declaration like “The check1 rule is listed before the check2 rule in the check inserting it into rulebook.” This is awkward and you might have to do it a lot, but it lets you get the ordering you want.