getting off the couch

If you’re sitting on a couch in a large room, and you want to interact with something that’s far away from you, you’d first have to get off the couch, right? Like say, you’re sitting on the couch, and you see a book you want to read that’s ten feet away from you. Logically, you’d have to first get off the couch before you can even examine the book (given that it’s so far away from you).

Here’s the code I have so far:

Place is a room.  "On one side of the room, you can see a couch.  On the opposite side of the room, you can see a book."

A couch is an enterable scenery supporter in Place.  The description of the couch is "It's a couch."

A book is in Place.  The description of the book is "It's a book."

Before doing something when the current action is not entering the couch:
	if the player is on the couch:
		try getting off the couch.

This gives me a run-time error. I’m guessing I’ve somehow created an infinite loop of getting on and off the couch or something, but I don’t know. Mainly, I just want the parser to automatically make the player “(first getting off the couch)” before doing anything else. It also might be nice if I could allow the player to interact with objects near or on the couch, or carried by the player when on the couch, since that technically wouldn’t require getting off the couch first. How would I do this? Thanks in advance! You all are always so helpful and informative, and I’ve learned a lot from you all in the three months since I’ve begun writing IF.

Yup, that’ll give you an infinite loop. “Try getting off the couch” runs through the whole action mechanism, which means it runs through the “Before” rules, and since it’s not entering the couch, that rule runs, which means you try getting off the couch again… and so on.

If you had to do this by hand, the thing to do would be to define a kind of action that required you to get off the couch (or one that didn’t) and make sure that your before rule runs only when the action is one that requires getting off the couch.

Fortunately, though, Inform has something built-in that should take care of your needs: the reaching outside rules. (See §12.16 of Writing with Inform.) These will run when the action is something that requires a touchable object–so you don’t need to get off the couch to look at the wall–and the player is in/on the couch (or whatever) while the noun is outside the couch. So that should take care of your needs!

Just make the rule for reaching outside the couch have the player try getting off the couch, silently so you don’t get a bunch of extra messages beyond “(first getting off the couch),” and also make sure that the player is off the couch so you can deny access (which stops the action) if they didn’t manage to get off. You could modify this rule to allow interacting certain other things (ones that you think of as near the couch) by including a test which lets you “allow access” before you try getting off the couch. And there are some things that you shouldn’t be able to do on the couch anyway, so you can write rules for those. :wink:

[code]The Green Room is a room. “A room for waiting, with a painting on the wall.” A painting is scenery in the Green Room. The description of the painting is “Nice painting.”

The couch is an enterable supporter in the Green Room.

Rule for reaching outside the couch:
say “(first getting off the couch)[command clarification break]”;
silently try getting off the couch;
if the player is on the couch:
deny access.

The player carries a rock.

Test me with “drop rock/sit on couch/look/get rock/sit on couch/x painting/drop rock/look/get rock/jump”.

Instead of jumping when the player is on the couch: say “Who do you think you are, Tom Cruise?”[/code]

…this does allow examining things that are in the room. You could define another rule that stops the player from examining something when the player is on the couch and the noun isn’t, or make this rule only for things you’ve defined as distant from the player, or small and distant from the player, or something. But the “reaching outside” rule will take care of most of it.

worked perfectly, thanks matt! I was even able to make an endtable and allow access if the noun is on the endtable. :slight_smile:

One thought:

Keep in mind that getting extremely finicky about minor game actions like not being able to reach the remote when the player is already sitting on the couch is a lot of work for something that’s just going to frustrate players. In real life, it’s kind of implicit that I’m going to stand up and grab the remote if I can’t reach it from the couch. It’s a little like coding that the player must TURN DOORKNOB before they can open a door. Ease of play should usually trump micro-detailed realism.

If there’s a plot related reason they can’t reach from the couch (such as the player has been wrapped in duct tape by the villain) then it’s justified.

well, the game i’m designing is a one-room game, and before implementing the code, i was able to perform all the commands while still sitting on the couch, like opening the freezer or turning on the stove or taking the gun off the mantle. i didn’t notice it at first, but then when i did, it made the whole thing feel unrealistic to me. i figured if the parser automatically moves the player off the couch in order to interact with the objects around the room, the player won’t have to worry about typing in the extra command, which would hopefully be less frustrating. what do you think? is implementing the code worthwhile for things like this? or should i just leave it out?

I think it’s worthwhile, if the player has reason to be on the couch at some point, and if the parser can automatically get them off the couch before doing things rather than just giving them a refusal.

Since the solution is fairly straightforward and easy, I would say that it is worth doing. I agree with you that it helps with the sense of realism. I have a very similar situation in my game–it just doesn’t feel right that the player should be able to interact with something on one side of the room if they are sitting/lying on a supporter on the other side of the room. At the moment I just have the game giving a flat refusal (“You can’t reach that from the bed”), but after stumbling on this thread I now see that there is a much better way. So, thanks for asking the question, and thanks to matt for the answer!

Oh definitely.

I’d probably give items an adjective and trigger an automatic exit if the player tries to interact.

[code]
A thing can be couchdistant.

The refrigerator is couchdistant.

Before doing something to a couchdistant thing when the player is on the couch:
say “(first getting up from the couch)”;
try silently exiting.

Before doing something to a thing enclosed by a couchdistant thing when the player is on the couch:
say “(first getting up from the couch)”;
try silently exiting.[/code]

It might be “before doing anything to a thing…” but it should be doable.