Able to get object while in a chair

My room has a table in the corner on which there is a kettle. The room also has a chair which can be “entered”. But the player is able to type get kettle and take it, even though they are in the chair!

See the screenshot for an example. Is there a way to make the parser stop the player from getting any object that’s not in the chair?

1 Like

Is it important that the player be able to sit in the chair? If not, you could simply eliminate it and give a “You don’t feel like sitting” response if the player tries to sit.

Also, you could put a tag on the player while on the chair.

A chair is here. It is a supporter. It is enterable. The description is "a chair.".

A widget is here. The description is "a widget.".

A person can be sitting or standing.

Carry out entering the chair: now the player is sitting.

Carry out getting off the chair: now the player is standing.

Check taking something: 
	if the player is sitting:
		say "You can't get that from here!";
		stop the action;
	otherwise:
		continue the action.

It would be easier (and less error-prone) to write “Check taking while the player is on the chair: …”

You may also want to read up on the “reaching outside” rulebook (chapter 12.16 to 12.18).

1 Like

This is an Inform 6 question, correct?

The default spatial model assumes that all objects in the same room are close enough to reach from any part within it. I don’t believe that there’s a direct analogy to I7’s reaching inside rules in the Standard Library. However, relatively straightforward code can do the trick. This example uses a before() routine applied to the room in question, which makes use of the Standard Library’s CommonAncestor() routine:

Constant Story "Reaching the Kettle";
Constant Headline "^from https://intfiction.org/t/able-to-get-object-while-in-a-chair/52586^";

Include "Parser";
Include "VerbLib";
Include "Grammar";

Class Room
    has light;

Room Start "Starting Point"
    with    description
                "An uninteresting room.",
            before [;
                Take:
                    if ((parent(player) ~= self) &&
                        (CommonAncestor(player, noun) == self))
                        "You can't reach ", (the) noun, " from where you are.";
            ];

Object chair "chair" Start
    with    name 'chair'
    has     enterable supporter;

Object table "small table" Start
    with    name 'small' 'table'
    has     static supporter;

Object kettle "white tea kettle" table
    with    name 'white' 'tea' 'kettle'
    has     container;

[ Initialise ;

    location = Start;

];

EDIT: I’ve made some small changes to the relevant code for minor improvements in efficiency.

Note that this is a plain vanilla I6 solution (Inform 6.31, StdLib 6/11). There may be better options when using Puny Inform, or when using the latest version of the Standard Library.

For a more advanced solution, you may want to look at Marnie Parker’s outofrch.h library, available from the IF Archive. It was originally written in 1999, so it may need some adjustments for compatibility with Glulx and/or Puny Inform.

5 Likes

Sigh, I missed the crucial detail (Inform 6) again. Sorry.

(Hint: If you include the relevant part of your source code, nobody will ever make this mistake. Also helps in case someone wants to test it.)

2 Likes

I can just confirm that this solution works fine in PunyInform, and I think it’s a good solution both for standard Inform 6 and for PunyInform.

If you have enterable containers all over the game, you may want to put the before rule in the Room class. Of course, this won’t be beneficial to game speed.

2 Likes