Discussion:
I7: newbie with simple question
(too old to reply)
rsmyth
2010-01-01 02:53:19 UTC
Permalink
Hi all,

I'm new to the forum and a raw beginner to Inform7. I've been inside
of the documentation all day and need to go to a New Year's Eve
party! Below is the code, which is an expansion of Stephen Granade's
Tutorial pub'd in the Brass Lantern (http://www.brasslantern.org/
writers/howto/i7tutorial.html). My problem is this: I want the
player to have to brush his teeth before going to bed. I want to set
the property on the teeth to be brushed after he brushes, but it's not
letting me use the "now" command. I also want the player to have to
"squeeze toothpaste"...

Thanks for any assistance, and apologies for any breach of
etiquette. -- Richard

<begin code>

"The Grand Tour" by Richard Smyth

The release number is 1. The story creation year is 2010. The story
headline is "A short I7 demonstration". The story genre is "Science
Fiction". The story description is "A small example of how to write
interactive fiction witn Inform 7".

When play begins: say "The intercom crackles to life. 'This is your
captain speaking. We're jumping to hyperspace shortly, so for your
protection, we've locked down all stateroom doors. As soon as we've
safely jumped, your doors will open and you will be free to move about
the ship.'"

CHAPTER 1 - THE GAME WORLD

The Stateroom is a room. "Staterooms aboard a spaceship, even one as
luxurious as the Thaleia, are tight, cramped affairs, and this one is
no exception. There is barely enough room for you and your furniture.
The door to the hallway is locked tight for now. East is your
bathroom."

The hallway door is scenery in the Stateroom. Instead of opening or
entering the hallway door, say "The captain has locked all stateroom
doors in preparation for jumping to hyperspace."

The Bathroom is east of the Stateroom. The description is "Like your
stateroom in smallness, only moreso. There is a mirror and one wall."

The shower is here. It is fixed in place. "Opposite the mirror is the
shower, which is closed." The description of the shower is "When it's
open, you get in it to take a shower. Right now it's closed. keeping
you from using it." Instead of opening or entering the shower, say
"It is locked down until after the ship makes its jump to hyperspace."

The sink is here. It is a supporter. "Just through the door is your
standard spaceship sink." The description is "There's a bit of hair
left behind from the former occupant."

The toothbrush is on the sink. The description is "A brand-new orange
Oral-B toothbrush that looks like a psychadelic spaceship."
Understand "toothbrush" as a toothbrush.

The toothpaste is an openable container on the sink. The container is
closed. The description is "Sensodyne, for those sensitive gums of
yours." Understand "a toothpaste" as toothpaste. Understand "tube"
as toothpaste.

The leaflet is in the Stateroom. The description is "It goes on and on
about how wonderful the Thaleia is. Should you have trouble sleeping
later, reading this could help."

The bed is an enterable supporter in the Stateroom. The description
is "Crumpled sheets indicate that the previous night of sleep was not
at all restful."
Understand "furniture" as the bed. Instead of looking under bed, say
"You see the requisite warren of dust bunnies huddling from your
judgmental glare." Instead of taking bed, say "Why would you want to
do that?" Before entering the bed, say "(first taking off your shoes
and socks)".

The mirror is scenery in the Bathroom. The description is "You look
tired after your long shuttle flight to the Thaleia."



[START SAMPLE CODE FROM DOCUMENTATION]



[END SAMPLE CODE FROM DOCUMENTATION]




CHAPTER 2 - CHARACTERS

Robutler is a man in the Stateroom. "Robutler stands attentive to your
needs." The description of Robutler is "Robutler has four arms,
treads, and a shiny metal body." Understand "robot" and "butler" as
Robutler.

Every turn:
if Robutler is not visible begin;
move Robutler to the location of the player;
say "Robutler rattles into the room, following you.";
end if.


CHAPTER 3 - THE SLEEP PUZZLE

At 9:05 AM: say "You realize that you are becoming exhausted."
At 9:08 AM: say "Your exhaustion is threatening to send you crashing
to the floor, unable to move."
At 9:12 AM: say "You are about to drop dead of exhaustion. You really
should get in bed."

At 9:15 AM:
say "You stumble to your knees and then collapse on the floor,
quite surprised to find that the phrase 'drop dead of exhaustion' can
be literally true.";
end the game in death.

Instead of entering the bed:
say "You climb into the bed, exhaustion overtaking you. You are
asleep before you can order Robutler to undress you.";
end the game in victory.


CHAPTER 4 - BRUSHING TEETH PUZZLE

Teeth is a kind of thing. Teeth is part of every person.

Teeth can be brushed or unbrushed. Teeth is usually unbrushed. The
description of teeth is usually "Not something you really want to be
looking at too closely."

The description of the player teeth is "Pearly white!"

The description of Robutler's teeth is "Pearly white! And why
shouldn't they be? He's a robot and doesn't eat anything..."

Instead of entering the bed when teeth is unbrushed:
if teeth is unbrushed,
say "Aren't you going to brush your teeth? Your last trip to the
dentist was not pretty.";
if teeth is brushed,
say "Smacking your lips from the taste of Listerine, you prepare to
climb in to bed."

Brushing is an action applying to two things. Understand "brush
[something]" as brushing. Understand "brush" as brushing. Understand
"brush [something] with [something]" as brushing.

Check brushing:
if the player is not holding a toothbrush, say "You're going to need
a toothbrush to do that." instead.

Carry out brushing:
if teeth are unbrushed, say "You vigorously brush your teeth the way
the orthodontist taught you, in an up-down fashion rather than a back-
and-forth fashion. Nothing can be more important than good hygiene!";

After brushing:
say "Now you're ready for bed."

Instead of brushing teeth when the toothpaste is closed:
say "You need to open the toothpaste first!"

<end code>
Jim Aikin
2010-01-01 07:27:47 UTC
Permalink
The basic problem you're seeing here is that you've made teeth a _kind_
of thing. Most Inform newcomers trip over this one. You've given the
player teeth, but they're an anonymous object, so you have to do a
little song and dance to get the compiler to understand what you're
Post by rsmyth
if teeth is unbrushed,
say "Aren't you going to brush your teeth? Your last trip to the
dentist was not pretty.";
...and the reason is because, what teeth are you talking about? The
compiler doesn't know.

I reorganized the last part of your code, making an assortment of
changes, which you might find helpful. It now seems to do what you
wanted. Here's the new stuff:

[Getting rid of this Before rule, because it will run even if the player
_isn't_ getting in bed.]
[Before entering the bed, say "(first taking off your shoes and socks)".]

[I commented out this rule, because I wrote a new one, below.]
[Instead of entering the bed:
say "You climb into the bed, exhaustion overtaking you. You are
asleep before you can order Robutler to undress you.";
end the game in victory.]

CHAPTER 4 - BRUSHING TEETH PUZZLE

[This is not better way to do the definition, by the way. It makes the
teeth plural.]
Some teeth are a kind of thing. Some teeth are part of every person.
The printed plural name of teeth is "teeth".

Teeth can be brushed or unbrushed. Teeth is usually unbrushed. The
description of teeth is usually "Not something you really want to be
looking at too closely."

[This is not needed. It never prints for some reason, probably because
the teeth are a kind.]
[The description of the player's teeth is "Pearly white!"]

The description of Robutler's teeth is "Pearly white! And why
shouldn't they be? He's a robot and doesn't eat anything..."

[Here's the main new stuff:]
Instead of entering the bed:
let T be a random teeth enclosed by the player;
if T is unbrushed:
say "Aren't you going to brush your teeth? Your last trip to the
dentist was not pretty.";
otherwise:
say "Smacking your lips from the taste of Listerine, you climb into
bed. You're asleep before you can even order Robutler to undress you.";
end the game in victory.

Hope this helps!

--Jim Aikin
Jim Aikin
2010-01-01 07:55:28 UTC
Permalink
Oh, by the way ... if you're going to refer to the taste of Listerine,
you should probably give the player a bottle of the stuff and make him
rinse with it or something.

And then there's flossing. Don't forget to floss!

--JA
rsmyth
2010-01-01 15:06:12 UTC
Permalink
Post by Jim Aikin
And then there's flossing. Don't forget to floss!
Getting him to brush is all I can handle for now! I'll save flossing
for later....

Thanks for the code suggestion. Did you run this? When I ran it, I
got an error message about "enclosed":

Problem. You wrote 'let T be a random teeth enclosed by the player' :
but assertions about the initial state of play must be given in the
present tense, so 'The cat is in the basket' is fine but not 'The cat
has been in the basket'. Time is presumed to start only when the game
begins, so there is no anterior state which we can speak of.

I looked up "enclosed" and "enclosure" in the documentation, but it
wasn't very helpful. I tried making it present tense by making it
"which is enclosed", but that didn't help. I also tried adding a line
like "Every person encloses teeth." I also searched some of the
example code posted at the Inform site, but there aren't a lot of
instances of enclosure.

Thanks for any additional help you can provide.

--Richard
Al
2010-01-01 15:56:43 UTC
Permalink
Another way to do this would be:

Bathroom is a room.

a toothbrush is in Bathroom.
the description is "It's an Oral-B.".

understand "brush"as the toothbrush.

brushing is an action applying to one thing.
understand "brush [something]" as brushing.
understand "brush [teeth]" as brushing.

the teeth is a thing.
the teeth is a part of the player.
the teeth is either brushed or unbrushed.
the teeth is unbrushed.

before brushing the teeth for the first time:
if the toothbrush is carried by the player begin;
now the teeth is brushed;
say "You brush your teeth. They become sparkly and clean once again.";
stop;
otherwise;
say "What are you going to use? Your finger?";
end if.

before brushing the teeth:
if the teeth is brushed,
say "You've already brushed your teeth.";
stop.

before sleeping:
if the teeth is unbrushed begin;
say "You need to brush the old choppers before sacktime.";
stop;
otherwise;
say "You hit the sack in preparation for tomorrow's grueling
activities.";
stop;
end if
rsmyth
2010-01-01 16:45:09 UTC
Permalink
Thanks for this latter suggestion. It runs and gives me some more
ways to tweak things.

Before you posted, I managed to fix my code using ch. 3.23 ("the parts
of things") chapter in documentation:

Teeth is a part of the player.

Teeth can be brushed or unbrushed. The description of teeth is
usually "Not something you really want to be looking at too
closely."

Instead of entering the bed when teeth is unbrushed:
if teeth is unbrushed,
say "Aren't you going to brush your teeth? Your last trip to the
dentist was not pretty.";
if teeth is brushed,
say "Smacking your lips from the taste of Listerine, you prepare to
climb in to bed."

Brushing is an action applying to two things. Understand "brush
[something]" as brushing. Understand "brush" as brushing. Understand
"brush [something] with [something]" as brushing.

Check brushing:
if the player is not holding a toothbrush, say "You're going to need
a toothbrush to do that." instead.

Carry out brushing:
if teeth are unbrushed, say "You vigorously brush your teeth the way
the orthodontist taught you, in an up-down fashion rather than a back-
and-forth fashion. Nothing can be more important than good hygiene!";
now teeth are brushed.

After brushing:
say "Now you're ready for bed."

Instead of brushing teeth when the toothpaste is closed:
say "You need to open the toothpaste first!"
Jim Aikin
2010-01-01 16:45:43 UTC
Permalink
Post by rsmyth
Thanks for the code suggestion. Did you run this? When I ran it, I
Yes, it runs here. The problem is very likely that you've got the
indentation wrong. Like most compilers, Inform's is not always able to
spot the real problem.

Writing it as "let T be a random teeth that is part of the player" also
works, and is easier to read. I often use "enclosed by" because it's a
grab bag that includes carrying, wearing, being a part of, and
indirectly holding. For instance, if Bob is carrying a basket and the
peach is in the basket, the room encloses the peach -- but the peach
isn't "in" the room. Only Bob is in the room.

--JA

Loading...