Login
Remember
IF Answers
Ask a Question

# Multiple issues in this code about putting things under a bed.

0 votes
48 views
asked Aug 22 in Authoring by eduardomezencio
edited Aug 22

I'm trying to learn Inform7, so some things here can be a little too noobish.. here is my source code of a room with a bed that can have things on it and under it:

    Room 1408 is a room.

    A bed is a kind of supporter. A underbed is a kind of container. It is a part of every bed.

    Understand "examine under [something]" as looking under.
    Instead of looking under a bed:
        if there is nothing in a underbed (called underbed) which is part of the noun:
            say "There's nothing under the [noun].";
        otherwise if there is something in a underbed (called underbed) which is part of the noun:
            say "Under the [noun] you see: [list of things in underbed].".

    Understand "put [something] under [something]" as hiding it under.
    Understand "place [something] under [something]" as hiding it under.
    Understand "hide [something] under [something]" as hiding it under.
    Hiding it under is an action applying to two things. Report hiding something under something: say "Under the [second noun] is probably not the best place to hide the [noun].".

    Instead of hiding something under a bed:
        if there is a underbed (called underbed) which is part of the second noun:
            now the noun is inside the underbed;
            say "You have placed the [noun] under the [second noun].".

    The wooden bed is a bed in room 1408. The pillow is on the wooden bed. The ball is in the wooden bed's underbed.

The issues:

1 - To make this possible, I created a strange object called underbed to represent the stuff under the bed. I would like to make it impossible for the player to refer to this object directly (e.g. examine underbed), so that the only way of interacting with it is using "under the bed". How can I do this? (EDIT: One of the things I tried was to use 'A underbed is a privately-named kind of container', but it does not work)

2 - If I start the game and type 'take ball', it will work. But I would like to forbid this, because the player should not be able to take the ball before knowing that it is there (the ball is hidden under the bed). If the player enter 'take all', the ball should not be revealed also.. How can I do this?

EDIT: I was able to solve the second issue myself by putting the ball under the bed only after the player looks under the bed for the first time. Still, if there's a better way to do this, I would like to know.

3 - This is a smaller issue, but in the line that starts with 'otherwise...' I had to write all of that instead of just 'otherwise: ' because it would not recognize underbed, but I think it should, because of the "(called underbed)" in the if statement. It is working well the way it is now, but this looks like a bug to me. Is it?

Thanks.

- inform7

## 2 Answers

0 votes
answered Aug 22 by Ryan Veeder (290 points)

1: To make underbeds privately-named, you can add the sentence "An underbed is usually privately-named."

2: In a game where I only had to worry about a single item underneath a bed, I handled it like this:

Instead of looking under the bed the first time:
say "You poke your flashlight under the bed and wave it around. Something catches the light: a key![paragraph break]Probably pretty obvious, but to pick up the key you'll want to type in 'pick up key' or 'take key'.";
now the brass key is in the location;

This doesn't simulate the underside of a bed as a separate place, though. If I were making a game where there were a lot of beds that needed looking under, and where the difference between being under the bed and just lying on the floor was important, I might handle it like this:

    A bed is a kind of supporter. An underbed is a kind of container. An underbed is part of every bed.

    Being under relates various things to one bed. The verb to be under means the being under relation.

    The wooden bed is a bed in room 1408.

    The ball is under the wooden bed.

    Instead of looking under a bed:
        let underside be a random underbed that is part of the noun;
        repeat with article running through things under the noun:
            now article is in underside;
            now article is not under the noun;
        try searching underside.

    Instead of searching an underbed:
        say "Under the bed you see [a list of things contained by the noun]."

I've created a new relation, "being under." When I say "the ball is under the wooden bed," I'm not really putting the ball under the bed; I'm "marking it" so that when I look under that bed, the ball will appear there. (The "now article is not under the noun" part is misleading: I have to delete that relationship, otherwise, if I move the ball, it'll zip back underneath the bed the next time I look there.)

3: I think the thing in the "otherwise if" line is working as intended. The "(called underbed)" in the if statement only propagates that definition within its own jurisdiction. When you get to "otherwise if...", that definition no longer applies.

There's some confusion due to the fact that your temporary name "underbed" is the same as the kind name "underbed". When the game tries to print "[list of things in underbed]" after it's forgotten your temporary definition, it produces "wooden bed's underbed."

I thought this must be the list of things in the category of "underbed," that is, the list of underbeds in the game. But I was wrong! I added a "gross bed" and a "holy bed" to the game, and when I looked under the wooden bed (with the "otherwise" line reading only "otherwise:"), I got:

"Under the wooden bed you see: wooden bed's underbed, gross bed, gross bed's underbed, holy bed and holy bed's underbed."

So I have no idea what's going on there. But here are my tips:

- Use temporary names that are distinct from property names. This makes it a lot easier when you're diagnosing bugs, not to mention just reading your own code!

- Declare those temporary variables each on their own line (instead of on an "if"/"otherwise" line) if you can, and as early in the rule as possible. I had to correct myself when writing my "instead of looking under a bed" rule: I put "let underside be a random underbed that is part of the noun" inside of the "repeat" section, and then I realized I'd also need it later on.

commented Aug 22 by eduardomezencio (36 points)
Thank you very much! It's a great answer.
About the 3rd item, this strange output you got is the same I was getting. Very strange, indeed.
Most importantly, about the first item, there is no way to make it privately-named because the underbed is a kind, not a thing. I tried it in a lot of ways to no avail. I'll put the solution that worked for me in another answer to help people with the same problem, but it is not a really great solution, just works.
commented Aug 22 by Ryan Veeder (290 points)
"An underbed is a kind of thing. An underbed is usually privately-named." compiles and behaves properly in builds 6G60 and 6L38, as far as I can tell.
commented Aug 22 by eduardomezencio (36 points)
You're totally right! Thanks. Sometimes inform can be quite unforgiving with syntax.
Btw: I asked this question before creating my account, and now the option for selecting your answer as best answer does not appear anymore :(
commented Aug 22 by Ryan Veeder (290 points)
That's okay. In my heart, I know that my answer is fantastic, and that's all that matters.
0 votes
answered Aug 22 by eduardomezencio (36 points)

For the first problem, what I did was:

    Instead of doing something to a underbed:
        say "You can't see any such thing."

It solved the problem.

commented Aug 22 by eduardomezencio (36 points)
But the way described by Ryan Veeder in a comment under his answer is better.

## Related questions

- How do I make this specific code work?
- Reset most of the things in the game to their initial conditions.
- How to output multiple messages without allowing actions in between?
- Inform 7: Multiple instances of a kind of thing where some (but not all) change properties
- Stopping a message from being said multiple times (Inform 7)?

...