Allow interactions with items only if they're 'In Reach'

I want to limit what the player can interact with when they’re sitting on the bed. There’s a bedside table which has stuff they can interact with, everything else is out of reach.

I’m using this code to manage that:

A thing can be reachable from bed.
Instead of doing something to anything not reachable from bed when the player is on the bed and the action requires a touchable noun,
	Say "You'll have to get off of the bed first."
Instead of going when the player is on the bed, instead say "It's hard to walk somewhere when you're on your bed..."

It’s functionally working, however, I have a few things to tidy up that my I7 experience doesn’t know how to.

  1. When I go West, between which there is a closed door, I get this output:

w
(first opening the Sliding Door)
You’ll have to get off of the bed first.

x door
the sliding door’s description. It is closed

It’s a little confusing stating that the door is being opened when in actuality the action does not succeed.

  1. I need to modify the reachable from bed state for objects as the player interacts with them. Currently, everything on or in the bedside table is hard-coded the property ‘reachable from bed’ - is there a cleaner way to do so, such as claiming everything on the table is reachable from bed? Also, an item carried should be reachable obviously and an item dropped while on the bed should be too - however, if it is dropped on the floor while standing, it should not be.
1 Like

You’re pretty close to what you want. Fortunately, the remainder of what’s needed is easy to do, and you can dispense with the ‘reachable from bed’ flag. Inform already tracks everything that we’ll need to check for us. Coming up is an example blob of code that does what you want. In the example, I’ve set it to automatically get up from the bed when you need to, rather than just say ‘You need to get up first.’ This seems more player-friendly, but you can just replace those two lines with your ‘instead’ if you want. A bit of general explanation after the code:

Bedroom is a room. 

Jim is a man. The player is Jim.

Jim carries a book.

a bed is an enterable supporter in bedroom.
Jim is on the bed.

a sheet is on the bed. "There's a sheet on the bed.".

a stapler is in bedroom. "A stapler lies on the bedroom floor.".

Before doing something to anything when the player is on the bed:
	if the action requires a touchable noun:
		if the noun is not on the bed and the noun is not enclosed by the player:
			say "(first getting off the bed)";
			silently try exiting;

Test me with "get sheet/drop book/get stapler/drop sheet/get on bed/examine sheet/get sheet".

So, we use a Before rule to catch the naughty actions, rather than an Instead, because by using Before we can have the player take an action in advance of trying to complete the original action. In this case, making the player get out of bed automatically.

As you can see, the first qualifiers are basically the same ones you wrote… doing something to anything, while on the bed, if the action requires something touchable.

The new qualifiers check where the object is. This replaces your flag system. So if the item is enclosed by the player (they could be holding it, wearing it, or it could be a part of them) I let the attempted action proceed.

The only other check I make is asking whether the object is on the bed itself. Summarily, if the player possess the object, or it’s part of the player, or it’s on the bed, I let the action proceed as normal.

If it failed one of the above checks, I’m assuming the object is just in the room itself, so then I make the player get off the bed, then allow the original action continue to be attempted.

The tests demonstrate all of the above cases, and also that the player can safely examine things that aren’t on the bed from the bed.

This code isn’t bulletproof for all situations, but if your game requires more complex checks than these, you can add those clauses to the Before rule of the code.

-Wade

1 Like

Thanks so much, this was exactly what I needed! It seems so obvious now…