Inform 7 help needed

I have been reading Jim Aiken’s wonderful book “The Inform 7 Handbook.” In it, he gives an example of how one might go about setting a little red barn as an room in a Farmyard. We want the player to be able to not just go north to enter the barn, but to be able to type “enter the barn” and “go inside” and so forth.

So we have this:

The Farmyard is a room. “A muddy farmyard. A little red barn stands to the north.”

The barn-exterior is scenery in the Farmyard. The description is “The barn is freshly painted a
cheerful bright red.” Understand “little”, “red”, and “barn” as the barn-exterior. The printed name of the barn-exterior is “little red barn”.

Little Red Barn is north of the Farmyard. “In the barn you can see some stalls and some hay.”

Instead of entering the barn-exterior:
try going north.
Instead of going inside in the Farmyard:
try going north.
Instead of going outside in the Little Red Barn:
try going south.
Instead of exiting in the Little Red Barn:
try going south.

I understand this example code, and it all works as expected. However, I noticed that if the player enters the barn, they will exit if they just type “exit.” If they type “exit barn” then they get the message, “I only understood you as far as wanting to exit.”

So I figured I would add this:

The barn-interior is scenery in the Little Red Barn. Understand “little”, “red”, and “barn” as the barn-interior. The printed name of the barn-interior is “little red barn”.

Instead of exiting the barn-interior:
try going south.

However, this did not work. The source failed to compile, giving this error:

Problem. You wrote ‘Instead of exiting the barn-interior’ , which seems to introduce a rule taking effect only if the action is ‘exiting the barn-interior’. But that did not make sense as a description of an action. I am unable to place this rule into any rulebook.

I don’t understand why “Instead of entering the barn-exterior” works fine, but “Instead of exiting the barn-interior” fails. Isn’t exiting a defined action already, just like entering?

The way “exiting” is defined as a standard action, it’s an action applying to nothing, like waiting or looking. The action exits whatever you are in; you don’t specify the thing that you want to exit. So Inform can’t understand “exiting the barn-interior”; as far as its grammar goes, it’s just like “waiting the barn-interior.”

This is also why you get the “I only understood you as far as wanting to exit” message; “exit” is a valid command but “exit barn” isn’t.

Exactly how to take care of this is a bit complicated. Emily Short’s Modified Exit extension uses the “getting off” action, which does take a noun, to handle cases like “exit platform.” You might want to look at how it does that (it’s in section 1 of the extension’s code; the extension is available from the Public Library or maybe built in, I don’t have Inform installed on this machine to check). If you were to use Modified Exit you could write a rule about getting off the barn-interior.

In your example the author sets up a room “Little Red Barn” that is north of the room “Farmyard”. The thing “barn-exterior” is scenery in the Farmyard that gives you something to examine/smell/taste but if you try to enter it the instead statements redirect you to the room “Little Red Barn”. You are trying to define a barn interior, but I think you just mean the room “Little Red Barn”. If you want to create a thing that the player can enter, you can create a scenery object and a redirect the player to a room, as the author did with the “barn-exterior” and “Little Red Barn”, or you can make the thing an enterable container (e.g. The tent is an open openable enterable container in the Farmyard.) If you want the player to be able to type “exit something”, one option might be to try something like this:

[code]Understand “exit [a container]” as specifically_exiting.
Understand “get out of [a container]” as specifically_exiting.
Understand “exit [a supporter]” as specifically_exiting.
Understand “get off [a supporter]” as specifically_exiting.
Understand “get off of [a supporter]” as specifically_exiting.

Specifically_exiting is an action applying to one thing.

Check specifically_exiting:
if the player is enclosed by the noun:
if the noun is not the holder of the player:
say “You must [if the holder of the player is a supporter]get off of[otherwise]get out of[end if] [the holder of the player] first.” instead;
say “You are not [if the noun is a supporter]on[otherwise]in[end if] [the noun].” instead.

Carry out specifically_exiting:
try exiting.[/code]

I see. Thank you both. It makes sense now why the compiler is giving that error. Thank you for the suggestion about the extension, Matt. I will check that out. And thank you, gabba, for the code example. I will try playing around with it. I am completely new to Inform 7 and there’s a great deal to learn.

If you alter your world model to use inside/outside instead of north/south, you can use this little gem:

Instead of exiting when the player is not in something:
	Try going outside instead;

You don’t need two insteads, and you might want to be careful because I think “the player” is always “in” something, whether it be the location or a region…

Check exiting: if the player is not in a container: try going outside instead.

A container is more specific than “something”.

Your code worked, so I might be wrong. In any case, you shouldn’t need to end an instead rule with “instead”.