Leaving a vehicle

I’m fairly new to Inform 7, but I love the natural language development.

My current issue is having the player in a car, and allowing the player to decide when they want to leave the car. I’m not a huge fan of using cardinal directions in every instance, so I want the player to be able to exit the car naturally.

I have written some code that works with ‘go outside’ and ‘exit the car’, but am having issues with ‘leave the car’.


Instead of exiting when the player is in the car: say "You open the driver's side door and step out onto the gravel driveway. "; move the player to the driveway.

This code works fine for ‘exit’, but not for ‘exit the car’.

I really don’t want to have to resort to east or west when leaving a car is so fundamentally easy without having to move a cardinal direction. I have set up the driveway as a room not attached to the car by a direction.

Also, introducing a ‘door’ into the scenario requires me to connect ‘the driveway’ and ‘the car’.

Some guidance in this situation would be greatly appreciated.

In an empty project, the actions tab of the index lists leave'' as a synonym forexit’’, which in turn does not take a direct object. So neither exit the car'' norleave the car’’ should work unless you or an extension define a new action. See WI 12.7 and WI 16.2.

Have you defined the car as a room or as a vehicle? A vehicle is a container that the player can enter and drive from room to room (which you may not want if the car isn’t driveable in your game). From what you’ve said it kind of sounds like you’ve got the car as a separate room rather than an enterable vehicle or an enterable container; maybe having it as an enterable container/vehicle would work better for you.

If you have the car as a container/vehicle, you might try including the extension Modified Exit by Emily Short (this is already installed as a built-in extension). It includes this code:

[code]Section 1 - Leaving a named object

Understand “exit [thing]” as getting off. Understand “get out of [thing]” as getting off.

This is the new can’t get off things rule:
if the actor is on the noun, continue the action;
if the actor is carried by the noun, continue the action;
if the actor is in the noun, continue the action;
stop the action with library message getting off action number 1 for the noun.

The new can’t get off things rule is listed instead of the can’t get off things rule in the check getting off rules.

This allows commands like “exit the car” to have the player leave the container.

If you have the car implemented as a room, then you don’t need to use a compass direction to connect the car and the driveway; you can say “The car is inside from the driveway” or “The driveway is outside from the car” and then the player will be able to navigate between them by “in” and “out” (and “go outside” will be understood as going out without your custom code).

You might still, however, have trouble with commands like “exit the car,” because the car is a room and actions like exiting or getting off (and all the commands that might profitably be redirected to them) don’t apply to rooms. As eu says, you’d have to define a new action. And there’s an additional complication that rooms by default aren’t in scope, meaning that the parser won’t understand the name of a room even when you’re in it. I’ve mocked up a quick demo that does some of the stuff you need below, but it might be simpler to make the car an enterable container.

[code]Include Modified Exit by Emily Short.

The Driveway is a room. “Your car is here.” The Car is a room. “You’re inside your car; the driveway is outside.” The Car is inside from the driveway.

Report going outside from the car: say “You open the drivers’ side door and step out onto the driveway.”

Room-exiting is an action applying to one object. Understand “exit [room]” as room-exiting.
Check room-exiting when the holder of the player is not the location: say “You’ll have to exit [the holder of the player] first.” instead.
Check room-exiting when the room outside of the location is nothing: say “I’m not sure which way you want to go.”
Carry out room-exiting: try going outside.

After deciding the scope of the player when the player is in the car: place the car in scope.[/code]

You might also try this, which is shorter and I think does more of what you want:

[code]Include Modified Exit by Emily Short.

The Driveway is a room. The car is an enterable container in the driveway.
Instead of going inside in the Driveway: Try entering the car.

(Why not just write commands that understand “exit the car” and “leave the car” directly? Well, you have to trap synonyms and articles; if your game understands “leave the car” but not “leave car” your players will hate you. And on my demo “get out of the car” isn’t understood and “get off the car” leads to a programming error, so there’s a lot to be done.)

This was fantastic advice. I made the car a container and things are much easier to control.

Thank you!

Sometimes, in this situation, I make the car a room but then add a “fake” car scenery object inside it. This lets you avoid the hassle of defining a new action and putting the room in scope.

The Car is inside from the Driveway.

The car-proxy is scenery in the Car. The printed name is "car".
Understand "car" as the car-proxy.

Instead of getting off the car-proxy:
	try going outside.

This handles the (built-in) “get off X” action. Since “get out of X” is more natural, I’d then expand the grammar to accept that.

Understand "get off/out of/from [something]" as getting off.

(This rather sneakily matches “get off of”, “get off from”, “get out of”, “get out from”.)

And while I’m at it:

Understand "exit [something]" as getting off.
Understand "exit from [something]" as getting off.

(This is some of the same stuff that’s in the Modified Exit extension.)