Feedback on IF exercise

Hi all,

I’m new at Inform, and was trying a simple exercise to get the hang of things. I wrote a story where the object is simply to make yourself a pb&j sandwich and eat it. I was wondering if anyone would mind giving me some feedback on the code. Inform 7 is very different from what I’m use to as far as programming languages go, and I just want to make sure I’m not doing anything silly or missing anything obvious. Any feedback would be greatly appreciated.

Source can be found at http://playfic.com/games/cadr/pbandj

Thanks!

Hey, nice coding! Just a quick response while I’m having breakfast…

The only thing I get an itch to change is how you handle the spreading. Inform 7 will happily handle a lot of the matching for you, so rather than having one big “check spreading” rule, you can have several rules with additional “when…” qualifiers, like

check spreading when the player does not have a knife:

Also, I think the general idea is not to actually do everything in the “check” rule, but handle that in the later stages - the “carry out” and “report” stages. So the “now the bread is off-stage” etc shouldn’t go inside a check rule.

  • Peter

Thanks - just the kind of stuff I was looking for!

I’ll read more about the carry out/report stages.

Started breaking the large check into smaller parts. I’m having trouble breaking this first "if’ condition out of the following (that checks that you have the bread on the plate and the plate on the counter):

Check spreading when the noun is jelly and the second noun is bread:
	if the plate is not on the counter or the bread is not on the plate:
		say "Like, in mid air?"; 
		stop the action;
	say "Jelly looks great on bread!";
	now the bread is jellied;
	if the bread is buttered:
		say "You now have a pb&j!  Hooray!";
		now the bread is off-stage;
		move sandwich to player;
	stop the action;

It is basically repeated for both jelly and peanut butter, and would be nicer separate. But the condition ends up with too many and/or and can’t seem to get it to work. I really want to write

Check spreading when the noun is in (jelly, butter), the second noun is bread, and either the plate is not on the counter or the bread is not on the plate:
	say "Like, in mid air?"; 
	stop the action;

but haven’t found a variation of that yet that the compiler likes.

The system works optimally when you don’t need to chain long conditions together, but they are caught by other rules. Here’s a complete example:

[code]
[I changed the action name to “spreading it on” so we can write rules like “report spreading jelly on bread” instead of the longer form “report spreading when the noun is…”]
Spreading it on is an action applying to two things.
Understand “spread [something] on [something]” as spreading it on.

Check spreading on when the player does not have the knife:
say “[one of]What, with like you hand or something? Weirdo.[or]Seriously, how do you think you are going to do that?[or]Really? You are really going to continue this weird utensil-less spreading campaign?[or]You really may need something to do that with…[stopping]”;
stop the action.

Check spreading something on bread when the plate is not on the counter or the bread is not on the plate:
say “Like, in mid air?”;
stop the action.

[It’s better to say “[the noun]” instead of “the [noun]” so that the article can be automatically dropped if the noun doesn’t need it.]
Check spreading on when (the noun is not jelly and the noun is not butter) or the second noun is not bread:
say “Why would you want to spread [the noun] on [the second noun]?”;
stop the action.

Carry out spreading jelly on bread:
now the bread is jellied.

Carry out spreading butter on bread:
now the bread is buttered.

Carry out spreading on when the bread is buttered and the bread is jellied:
now the bread is off-stage;
move sandwich to player.

Report spreading jelly on bread:
say “Jelly looks great on bread!”

Report spreading butter on bread:
say “The peanut butter spreads on smooth as… well, you know.”

Report spreading on when the bread is buttered and the bread is jellied (this is the report sandwich finished rule):
say “You now have a pb&j! Hooray!”

[We have to make sure this rule is considered last so that the messages are shown in the correct order.]
The report sandwich finished rule is listed last in the report rules.

[This is a special case so it’s easier to use an instead rule.]
Instead of spreading jelly on the counter:
say “That is how you get ants.”[/code]

Probably nitpicking here, but when you first open the breadbox, it says it reveals “a bread” . You could either say that the article is some, or make it a loaf of bread.

Juhana - wow, thanks, that helps so much!

masema - do you mean adding something like the following?

The indefinite article of bread is "a loaf of".

Also, I notice when I do “spread jelly on cupboard” it says “Why would you want to spread the jar of jelly on cupboard?”. I probably want it to say ‘jelly’ in that case. Any suggestions as to how to do that?

To Inform ‘jelly’ refers to the ‘jar of jelly’ object (since ‘jelly’ is part of its name). If the player doesn’t have to manipulate the jelly apart from the jar of jelly, you could try something like this:

The peanut butter is in the refrigerator. The indefinite article of the peanut butter is "[if not handled]a jar of[otherwise]some[end if]". The jelly is in the refrigerator. The indefinite article of the jelly is "[if not handled]a jar of[otherwise]some[end if]". Understand "jar" as the peanut butter. Understand "jar" as the jelly. This will print “a jar of jelly” (etc.) until the player takes the jar, after that it will print “some jelly” (etc.).

You also want the game to say not “Why would you want to spread the jar of jelly on cupboard?” but “Why would you want to spread the jar of jelly on the cupboard?” The reason it doesn’t is because you create the cupboard without an indefinite or definite article to go with it. The line that creates this things is The refrigerator, counter, breadbox, cupboard, drawer is scenery. . The fridge and the other scenery things are created by this line, since this is the first mention of those things in your code. And if a thing is created without using an article, Inform supposes it’s a proper name and won’t use the article when it prints the name of that thing.

You can fix this in two ways:

  1. by changing that line to read: A refrigerator, a counter, a breadbox, a cupboard, and a drawer is scenery. (with or with the word ‘and’ and using either ‘a’, ‘an’ or ‘the’ as you like);
  2. by moving the line, as it is, to some other place further down in your code (such as the very end of section 2), where the things you want to be scenery will already have been created by other lines using definite or indefinite articles.

You could also try something like this (untested):

Rule for printing the name of the jar of jelly when spreading: say "jelly". Rule for printing the name of the jar of peanut butter when spreading: say "peanut butter".

No, I meant make the thing a loaf of bread.
Like this

the loaf of bread is a thing.