Help with checking if the player is in a vehicle

Hey! I am making a game that involves driving in a car on a highway, and I want to make it so you can not enter the highway room if you arent in a vehicle. How can I do this? This is what I have right now:

Before going south:
	if the player is in the front yard:
		if the player is not going by a vehicle:
			say "You should get in your car before getting on the highway." instead;

and this is the error:

Problem.  In the sentence 'if the player is not going by a vehicle'  (line 49), it looks as if you intend 'player is not going by a vehicle' to be a condition, but that would mean comparing two kinds of value which cannot mix - a person and a described action - so this must be incorrect.



          
I was trying to match this phrase:



          
  if (player is not going by a vehicle - a condition): 



          
I recognised:



          
player is not going by a vehicle = a condition

Could use a bit of help here!

Try writing a “check/before going somewhere” rule and use “if the player is not enclosed by a vehicle” as the condition!

1 Like

Maybe something like this:

front yard is a room.
road is south of front yard.
car is enterable vehicle in front yard.

I’m using a check rule instead of before so that other before / instead rules
aren’t bypassed altogether… probably not necessary for this case, just
something I feel is a good habit.

Check going south from front yard when
  the vehicle gone by is not the car:

The going action has several useful variables defined. From the Standard Rules:

The going action has a room called the room gone from (matched as "from").
The going action has an object called the room gone to (matched as "to").
The going action has an object called the door gone through (matched as "through").
The going action has an object called the vehicle gone by (matched as "by").
The going action has an object called the thing gone with (matched as "with").

So from front yard is equivalent to when the room gone from is the front yard. You can’t use that shorthand with a negative, i.e., you can’t say not by the car, so I used when the vehicle gone by is not the car. If there’s more than one possibility for the vehicle in the game, it’d be better to go with vehicle like you had than to name the car itself like I did.

if the car is in the front yard begin;

We make sure it’s really there so we don’t do something nonsensical!

silently try entering the car;

Try getting in, silently, to suppress the normal response.

if the holder of the player is the car begin;

Straightforward test that getting in succeeded: are we in the car?

  say "(first entering the car)[line break]";

(Report the implicit entering car action.)

now the vehicle gone by is the car;
continue the action;

If we tried to continue the action without setting the vehicle gone by, the “can’t travel in what’s not a vehicle rule” would end up stopping us. We could’ve said instead try going south instead of now the vehicle gone by is the car; continue the action. That would start over with a new going action that’d work this time: this check rule won’t run this time because we’re really in the car now.

end if;
end if;
instead say "You'll want a car to get on the road."

If the above didn’t work, we say the above and end this action in failure.

Altogether from the top for ease of cutting-pasting into borogove.app or whatever…

front yard is a room.
road is south of front yard.
car is enterable vehicle in front yard.

Check going south from front yard when the vehicle gone by is not the car:
if the car is in the front yard begin;
silently try entering the car;
if the holder of the player is the car begin;
say "(first entering the car)[line break]";
now the vehicle gone by is the car;
continue the action;
end if;
end if;
instead say "You'll want a car to get on the road."
3 Likes

Thank you so much! That is a really great answer, thank’s tons.

Though there’s nothing wrong with Zed’s approach, I’d like to note that Check going by nothing will also work if you want a rule to fire when the player is not in a vehicle, as long as anything vehicle-like is sufficient to permit them to go. If you’re using Rideable Vehicles and you have rideable animals in your game and you don’t want the player to be able to enter the highway while riding an animal, then this approach won’t work. But if that’s not the case, this is shorter and in my opinion not significantly less clear. (Your mileage may vary on the clarity of it though.)

1 Like