Check if player has eaten a foodstuff before action

Hi,

Bit of a newbie question here. How can I check if the player has eaten the spinach before opening a door? If they have, the door opens, otherwise, say “you don’t have enough strength”.

Any help would be much appreciated. Here’s the code I have so far:


The can is on the table.
The can is a container.
The can is openable.
The can is closed.
The can is opaque.
Inside the can is spinach.
The spinach is edible.
After eating the spinach, say "You eat the spinach and feel envigorated and fortified."
The description of the can is "The label on the can reads: 'Class A Spinach - Gives you Strength and Vitality'."

The sewer is a room. "You are in the sewer. It has a most unpleasant odour and there are rats here."

The grate is a door. 
The grate is closed.
The grate is down from the kitchen and up from the Sewer.
The description of the grate is "The metal grate is heavy and rusty."

Before opening the grate:
	if player has eaten spinach:
		say "You easily lift the heavy grate.";
	else:
		say "you don't have enough strength to open the heavy grate.";
		stop the action.

Running the code produces the following error:

I was trying to match this phrase:

if (spinach is not eaten - a condition): 
This was what I found out:

spinach is not eaten = something unrecognised

How would I rephrase this condition: if player has eaten spinach ?

Many thanks.

‘If the spinach was eaten’ might work, but a truth state definitely would.

Enhanced-strength is a truth state that varies. Enhanced-strength is false. After eating the spinach: Now enhanced-strength is true. Instead of opening the grate when enhanced-strength is false: Say "No way.".

The built-in way of phrasing this condition is “if we have eaten the spinach”, but you have to be careful to make sure the eating action succeeds when you mean it to succeed.

The truth-state solution is wordier, but explicit.

Thanks for the help.

Yes I see, it looks like maintaining state values is the way to go. Blecki’s code works perfectly! Thank you :slight_smile: