Refill something

I have a bike with ignition switch, which works find. but in order for the player to ride they need to refuel it.

this is the code that allows bike to move which works i just need to have them refuel it.

The fuel tank is part of The Harley. The fuel tank has a number called fuel-remaining. The fuel-remaining of the fuel tank is 0.

when fuel is above 1 the the ignition turns on and bike moves.

So are you looking to create a refueling action? Or are you having trouble with the code for turning the ignition on when the fuel is above 1?

Here’s a fairly minimal version where we create a new action to allow the player to refuel the Harley (and potentially other things which have a tank).

Include Rideable Vehicles by Graham Nelson.

A tank is a kind of thing. 
A tank has a number called fuel-remaining. 
A tank has a number called max-capacity. 
[Both default to 0.]

The Gas Station is a room.

The Harley is a rideable vehicle in the Gas Station.
The fuel tank is a tank. It is part of the Harley. 
The max-capacity of the fuel tank is 5.

Refueling is an action applying to one thing.
Understand "refuel [something]" as refueling.

Check refueling:
	if the noun is not a tank and the noun does not incorporate a tank:
		say "That's not something you can refuel." instead.
        
Check refueling:
	if the location is not the Gas Station, say "You need to be at the gas station." instead.

Carry out refueling something which is not a tank:
	let T be a random tank which is part of the noun;
	silently try refueling T instead;

Carry out refueling a tank (called T):
	now the fuel-remaining of T is the max-capacity of T.

Report refueling:
	say "You refuel [the noun] to the max.".        

There are lots of ways to expand and refine this code. For example:

  • add synonyms for the action;
  • consider making a tank a kind of container (instead of a kind of generic thing);
  • there should be a check if the tank is already full;
  • you’ll probably want to add a possibility to refuel the bike from a fuel canister instead of needing to be at the gas station. Since handling liquids is a big topic in itself, I didn’t include that in this basic version. There’s a lot of helpful material on that in the Recipe Book at 10.2. Liquids.

Edited to add:
To prevent the player from using the Harley with an empty tank:

Check going somewhere by the Harley:
	if the fuel-remaining of the fuel tank is 0:
		say "Can't ride anywhere with an empty tank." instead.

Or a more generic version:

Check going somewhere by something which incorporates a tank (called T):
	if the fuel-remaining of T is 0:
		say "Can't go anywhere with an empty tank." instead.

(I didn’t tie this to an ignition switch, but the principle is the same.)

1 Like

Thank you.

1 Like