Inform 7 - interacting with items while in a car

Having trouble with a car that the player can enter, but can still interact with items while inside. I’ve tried Developing rules or carry outs that prevent this but inform is not accepting my wording. this is the current code:

In Parkade5 is a vehicle called Toyota Corolla. The description of Parkade5 is "[if unvisited]A car, which sits lonely by itself in the far corner of this level of the parkade, catches the flickering of the lights. [otherwise] Fluorescent lights falter ominously as they fail to illuminate the parkade." The description of Toyota Corolla is "The machine looks exactly as you would expect a 1998 Toyota Corolla to look.". Understand "car" and "Toyota" and "corolla" as Toyota Corolla. Understand "concrete" and "enclosure" and "concrete enclosure" as Parkade.
There are some keys inside the Toyota Corolla. Understand "keys" and "car keys" as some keys. The ignition is a device. The ignition is a part of Toyota Corolla. 
Understand "turn [something]" and "turn [something] on" as switching on. Understand "start [something]" as switching on. Instead of going by the Toyota Corolla when the ignition is switched off:
	say "The ignition is off."
Instead of switching on the Toyota Corolla, try switching on the ignition.
Instead of switching off the Toyota Corolla, try switching off the ignition.
Carry out turning ignition:
	say "Try switching the ignition".
Instead of moving:
	if the player is in Toyota Corolla:
		say "The car has to be on for you to drive it.".
Understand the command "drive" as something new. Driving is an action applying to one visible thing. Understand "drive" as driving. Understand "drive [something]" as driving.
Carry out driving:
	say "You need to start the ignition to drive.".

You can interact with items outside of the car because Inform doesn’t know this is not allowed. Something like this will disallow reaching outside of all vehicles.

TO reach is a verb.
The can't reach outside vehicles rule is listed last in the reaching outside rules.
This is the can't reach outside vehicles rule:
	if the holder of the person reaching is a vehicle:
		say "[The person reaching] [can't reach] [the noun] from inside [the holder of the person reaching]" (A);
	rule fails.

If you want this allowed sometimes, it’s easy enough to make exceptions to it using a kind or a specific object.

The can't reach outside vehicles rule does nothing when the holder of the person reaching is the bike. [(for example)]


A few potentially useful notes:

You’ve used a few “carry out” rules to tell the player something which suggests the action has failed ("try switching the ignition). You may want a check rule instead. “Carry out” rules are the part of action processing where Inform tries to make the action happen. If Inform is processing a “carry out” rule, it generally assumes that up to now the action has been successful, and nothing like the player not even being able to do that has stopped it. A check rule is frequently used where an action isn’t actually worth trying, because it won’t produce a meaningful result under the circumstances. A message like this wouldn’t be seen, because Inform already stopped the player from trying “turning the ignition”, not knowing what that would mean in context.

Have a look at this section of Writing with Inform for info on “check”, “carry out”, and “report rules”.

Your rule for “carry out turning the ignition” is also likely redundant. You’ve used an understand phrase to allow the player to type TURN ON IGNITION, which will switch it on. Having a rule which then tells them to “try switching it on” would be confusing, because if it were to ever run, Inform would already be trying that.

I’ve not said anything about your driving action, because it’s 5 AM and my mind is dissolving. But I hope this helped some.

EDIT: Added a link to WI12.9 which explains “check”, “carry out”, and “report” rules.

1 Like

It’s important to understand that the name of an action is a fixed thing to the Inform 7 compiler. The name is assigned when the action is created. Where you say

Driving is an action applying to one visible thing. Understand "drive" as driving. Understand "drive [something]" as driving.

you are creating the driving action. (Note that “visible” does not mean what it seems to mean, so it’s not necessary here. This is a very common mistake. See WWI 12.7 New actions for details. Also take a look at WWI 18.32 Supplying a missing noun/second noun if you want the command >DRIVE to work. WWI means “Writing With Inform,” the first half of the built-in documentation.)

Once you have created an action, multiple ways of generating an action within the story can be set up via various Understand... as... lines. You have some in your example above, but only the specific name used when creating the action will be understood as that action by the I7 compiler. The Understand... lines tell the story parser how to deal with player command input, not author code. So, where you say

Instead of moving:
    if the player is in Toyota Corolla:
	    say "The car has to be on for you to drive it.".

unless you’ve already created a new moving action somewhere, the compiler can’t understand this, because there is no the moving action.

Many actions are defined by the Standard Rules and exist by default. Your story will include the turning action by default. If you want >TURN CAR to only mean starting the ignition, you must first disconnect the command word “turn” from the turning action via Understand the command "turn" as something new. (See WWI 17.3 Overriding existing commands.) This should be done before your new Understand... lines. You are already re-establishing the other uses of the command word for switching on, but don’t forget the switching off action:

Understand "turn [something] off" or "turn off [something]" as switching off.

As rainmaze notes, it’s also important to understand the overall flow of rulebook processing for actions, so that you know which rulebook to use to get a particular effect. WWI 12.2 How actions are processed has a good overview at a high level, and there are other sections that cover the specific rulebooks in more detail.

In this case it is perhaps more helpful to redirect the player action to the correct one (see WWI 12.6 Spontaneous actions by other people for more):

Instead of turning the Toyota Corolla:
    try switching on the ignition instead.

Instead of turning the ignition:
    try switching on the ignition instead.

Under the Index tab, clicking the “Commands” box (in the orange “Actions” section) will show how command words map to actions. Be advised that unbinding the command word “turn” from the turning action doesn’t make the action disappear, and that the action can still be generated by >TWIST CAR or >SCREW CAR, as examples. So either of those will result in the ignition being switched on with those last two rules in place.


well, if we take “no interaction outside the car” as a premise, one can think about “finebait on turnpike 1” or something along this evil line or reasoning :smiley:

(there’s valid & consistent interacting from inside a car with things outside a car, thru the side window, one indeed being highway ticketing :wink: )

Best regards from Italy,
dott. Piergiorgio.

1 Like

Putting that in Inform7 responds with this:
" ‘To reach is a verb’ : but this is a phrase which I don’t recognise, possibly because it is one you meant to define but never got round to, or because the wording is wrong (see the Phrasebook section of the Index to check). Alternatively, it may be that the text immediately previous to this was a definition whose ending, normally a full stop, is missing?"

I imagine I could make reach into a new action, but this would make the interactions the player might attempt from inside the vehicle only disallowed if they use the command reach, right? Some of the actions that they could potentially use involve interacting with objects (e.g. swing set) and picking up objects. How would I prevent this?

Yes that’s true. However in the context of my game the car is used mainly for traveling from one area to another and for a scene, so interaction is never necessary from inside the car with objects or backdrops outside of it.

A verb is not the same as an action name. The To reach... line only sets up the ability to use [reach] in the adaptive text subsystem, which is used by the message to the player in the rule that rainmaze provided (in the form of [can't reach] in this case; see all of WWI 14 Adaptive Text and Responses for more).

The reaching outside rulebook is one of those that governs whether the player object is able to physically interact with another thing in the model world. These rules apply to any action that requires a touchable noun or second noun (touchable being the default for a new action; the visible keyword when defining an action means it’s OK for the action to apply to something that can only be seen, like water in a sealed glass bottle – that’s not the whole story but a good enough starting point). (See WWI 12.16 Reaching inside and reaching outside rules for more details.)

1 Like