Two or more people exit a car - Inform 7

If the player’s in a vehicle, then the player going somewhere automatically means going there in the vehicle. You don’t have to worry about moving the vehicle manually. I’m guessing you might have been doing things this way in an effort to restrict where the car could go and keep the player from driving into buildings. For that you could use something like (this presumes only the player will be driving):

City Streets is a region.
1st street is in city streets.

Check going when the player is held by the car (this is the city streets rule):
  if the room gone to is not in City Streets, instead say "You'll have to get out of the car."

Or if you’re like me and want the code to be as English-y as possible:

Definition: a room is offroad if it is not in City Streets.
Instead of going by car to an offroad room: say "You'll have to get out of the car first."
1 Like

Nice, I didn’t know going by car would work.

This solution to getting people out of the car works fine.

The next problem is if the player re-enters the car how can the people that got out the first-time re-enter with the player?

Hope this makes sense.

After entering the car when there is an other person in the location:
    repeat with the passenger running through other people in the location:
        try the passenger entering the car.
1 Like

Do you need to have the exact set of folks who were previously in the car then re-enter, or is it everyone who’s in the current location (like, there are no other NPCs who should stay outside the car)?

If the latter, that’s easy:

Last report entering the car:
	Repeat with passenger running through people in the location:
		Try passenger entering the car.

If the former, you’ll need to change the other rule to store a list of who was in the car. This pair of rules should work:

The passenger-list is a list of people that varies.

Last report getting off the car:
	Change passenger-list to have 0 entries; [clear out the previous list of passengers]
	Repeat with passenger running through people in the car:
		Try passenger getting off the car;
		Add passenger to passenger-list.
Last report entering the car:
	Repeat with passenger running through passenger-list:
		Try passenger entering the car.

Edit: ninja’d again!

1 Like

Thanks, the former part is what I am looking for.

I will try that.

I just tried it but got the following error:

Passenger Error

Not sure what I need to change in the code.

I think I need to define the passenger-list but I am not sure how.

Oops, I missed a line when I copied in my code – will edit that back in.

I have tried

Passenger-list is a list of text that varies. Passenger-list is {passenger}.

but also gives an error.

Right, that won’t work - the code I posted uses it as a list of people, not bare text. You need to tell Inform what kind of data goes in a list when you create it, and it’ll throw and error if you try to put the wrong thing in there.

EDIT: just realized that maybe you didn’t see my edit? The line you need to put in is “The passenger-list is a list of people that varies.”

1 Like

Thanks, I figured that out just before you edited your post.

It is working.