[solved] Trouble compiling I7 "Nickel and Dimed" recipe

My little brother is trying his hand at Inform 7 and I’m helping him debug his code. He’s copied all the essential parts of the “Nickel and Dimed” money-handling recipe from the documentation into his project, and placed an instance of a “dollar bill” kind – which is itself a kind of “money,” which is a kind of thing – in the game world. Upon compilation, these errors occur:

Any ideas?

We’d have to see more of the code. How are you placing the bill instance in the world?

Don’t have access to the project at the moment and will update this thread when I do, but I think it was something along the lines of:

The wallet is an openable closed container. A dollar bill called 1938 is in the wallet.

Hm. That should work; it does work, in my very stripped down example.

The Kitchen is a room.

Price is a kind of value. $10.99 specifies a price with parts dollars and cents. A thing has a price. The price of a thing is usually $0.00.
Money is a kind of thing. Coin is a kind of money.
A dollar bill is a kind of money. The price of a dollar bill is $1.00. The printed name of a dollar bill is "dollar bill". Rule for printing the plural name of a dollar bill: say "dollar bills". The description of a dollar bill is "It has George Washington's head on the front, which with a bit of creative folding can be scrunched to look like a mushroom. All important things really are learned in kindergarten."

The wallet is an openable closed container.
A dollar bill called 1938 is in the wallet.

To decide what money is the best money from (buyer - a thing) for (cost - a price):
	decide on nothing.

Alright, here’s all the code relevant to the monetary system. Most of it seems to be copied directly from the Recipe Book.

[spoiler][code]
Price is a kind of value. $10.99 specifies a price with parts dollars and cents. A thing has a price. The price of a thing is usually $0.00.

Money is a kind of thing. Coin is a kind of money.

A dollar bill is a kind of money. The price of a dollar bill is $1.00. The printed name of a dollar bill is “dollar bill”. Rule for printing the plural name of a dollar bill: say “dollar bills”. The description of a dollar bill is “It has George Washington’s head on the front, which with a bit of creative folding can be scrunched to look like a mushroom. All important things really are learned in kindergarten.”

The wallet is a closed openable container. The description is “Why is this wallet not guarded?” A dollar bill named 1931 is in the wallet.

A five-dollar bill is a kind of money. The price of a five-dollar bill is $5.00. Understand “five” or “five dollar” as the five-dollar bill. The description of a five-dollar bill is “Abraham Lincoln. He looks slightly less dignified here than he does on the penny.”

A hundred-dollar bill is a kind of money. The price of the hundred-dollar bill is $100.00. Understand “hundred” or “hundred dollar” as the hundred-dollar bill. Understand “dollar” as the dollar bill. The description of a hundred-dollar bill is “It’s got Benjamin Franklin, who always gets shafted: a denomination too large for anyone to carry conveniently, and a lot of local fame in Philadelphia.”

A quarter is a kind of coin. The price of a quarter is $0.25. The description of a quarter is “One of the old-fashioned variety, not a state quarter.”

A dime is a kind of coin. The price of a dime is $0.10. The description of a dime is “Franklin Roosevelt, trying not to look too annoyed that his coin is so small and thin.”

A nickel is a kind of coin. The price of a nickel is $0.05. The description of a nickel is “A chubby coin, but you’ve always liked Thomas Jefferson, and the Monticello on the back is a nice touch.”

A penny is a kind of coin. The price of a penny is $0.01. The description of the penny is “A profile of Abe Lincoln. Sometime soon they’ll stop minting these, you’re sure of it.”

Ownership relates one person (called the owner) to various things. The verb to own (he owns, they own, he owned, he is owned) implies the ownership relation.

Definition: a thing is owned if the player owns it.

Instead of buying something which is owned by the player:
say “You already own [the noun].”

Instead of going somewhere when the player encloses something (called the stolen goods) which is not owned by the player:
if the owner of the stolen goods is not a person:
now the player owns the stolen goods;
continue the action;
if the owner of the stolen goods can see the player, say “‘Hey there buddy, not so fast,’ says [the owner of the stolen goods]. ‘You going to buy [the stolen goods] first, or am I gonna call the cops?’”;
otherwise continue the action.

After taking inventory:
say “Altogether, you’ve got [the player’s cash] on your person.”

To decide what price is the player’s cash:
let sum be the total price of money enclosed by the player;
decide on sum.

To decide what price is the sum in (item - a container):
let sum be the total price of the money in the item;
decide on sum.

When play begins: now every thing carried by the player is owned by the player.

Definition: a thing is worthless if the price of it is $0.00. Definition: a thing is valuable if it is not worthless.

A thing can be for sale.

Rule for printing room description details of something (called target) which is for sale (this is the disclose prices in room description rule): say " ([price of the target])".

Before listing contents: group money together giving articles.

Instead of examining a for sale thing (this is the describe things by price rule):
say “[The noun] costs [the price of the noun], payable to [the owner of the noun].”
The cashbox is a container. The cashbox contains 999,999,999,999 pennies. The cashbox contains 999,999,999,999 nickels. The cashbox contains 999,999,999,999 dimes. The cashbox contains 1999,999,999,999 quarters. The cashbox contains 999,999,999,999 dollar bills. The cashbox contains 999,999,999,999 five-dollar bills.

The block buying rule is not listed in the check buying rules.

Check buying something:
if the noun is not for sale, say “[The owner of the noun] does not want to sell you [the noun].” instead;
if the player’s cash is less than the price of the noun, say “You can’t afford the asking price of [the price of the noun] for [the noun].” instead.

Carry out buying something:
let sum paid be $0.00;
while sum paid is less than the price of the noun:
let current target be the price of the noun minus the sum paid;
let bill offered be the best money from the player for the current target;
if the bill offered is money:
move the bill offered to the owner of the noun;
now the bill offered is spent;
increase the sum paid by the price of the bill offered;
let current target be the price of the noun minus the sum paid;
say “You hand [the owner of the noun] [a list of spent money]. [run paragraph on]”;
if the sum paid is greater than the price of the noun, let change be the sum paid minus the price of the noun;
if change is greater than the sum in the cashbox:
now the player carries every spent money;
now every spent thing is fresh;
say “‘Whoa,’ says [the owner of the noun], handing the cash back to you. ‘I can’t make change for that, man, sorry.’” instead;
now every spent thing is in the cashbox;
now every spent thing is fresh;
while change is greater than $0.00:
let change bill be the best money from the cashbox for change;
decrease change by the price of the change bill;
now change bill is spent;
move change bill to player;
if money is spent, say “[The owner of the noun] makes change with [a list of spent money]. [run paragraph on]”;
now every spent thing is fresh;
if the noun is not enclosed by the player and the owner of the noun can touch the noun:
say “‘Here ya go,’ says [the owner of the noun], handing [the noun] to you. [run paragraph on]”;
move the noun to the player;
now the player owns the noun.

Money can be spent or fresh.

Report buying something:
if the player owns the noun,
say “Your transaction is now complete, leaving you with [the player’s cash].”

            Definition: money is costly if its price is $2.50 or more. Definition: money is cheap if its price is $0.99 or less. 

Functional relation is a kind of value. The functional relations are overpayment, underpayment, or irrelevant. Money has a functional relation.

To decide what money is the best money from (buyer - a thing) for (cost - a price):
repeat with bill offered running through money:
if the bill offered is enclosed by the buyer:
if the price of the bill offered is the cost, decide on the bill offered;
if the price of the bill offered is greater than the cost, now the functional relation of bill offered is overpayment;
otherwise now the functional relation of the bill offered is underpayment;
otherwise:
now the functional relation of the bill offered is irrelevant;
if the total price of underpayment money is less than the cost:
decide on the cheapest money which is overpayment;
otherwise:
decide on the costliest money which is underpayment.

            Instead of giving money to someone:
    say "Best to keep the transaction simple by buying whatever you want"

[/code][/spoiler]

When I add this line to the end of the code you posted, it compiles successfully:

The Kitchen is a room. The player carries a wallet. A dollar bill called 1938 is in the wallet.

If I add the same line to the beginning of the code, it doesn’t compile, because the code hasn’t defined the kind “dollar bill” yet.

And if I comment out “A dollar bill called 1938 is in the wallet” it gives the same error you got.

So, maybe make sure source code ordering isn’t a problem, and make absolutely sure you’re creating that dollar bill? The code you posted seems fine.

I tried moving the introduction of the wallet and dollar bill to a point in the source code after the whole monetary system, but that didn’t seem to help. :confused:

At this point I’m guessing there is a bug in some seemingly unrelated part of the code, and the Natural Inform compiler is just being unhelpful about pointing out where the actual problem is, or that I’ve bumped up against some eldritch compiler bug.

Probably unrelated, but this code when it compiles creates a single object called “999,999,999,999 pennies” instead of actually creating that many individual pennies, and a good thing too. Same for the other things in the cashbox. (Inform doesn’t seem to recognize numbers with commas in them as numbers, and that is anyway too many damn pennies.)

The syntax in your brother’s code is slightly wrong in one place, it says “A dollar bill named 1931 is in the wallet.” (which creates an object called ‘dollar bill named 1931’ rather than a dollar bill called ‘1931’).
That ought to be “A dollar bill called 1931 is in the wallet.” (as in your own and zarf’s posts above).

Thanks! That was indeed the issue. Never would have caught that on my own. (Which is why I’ve switched back to Inform 6 for my own needs – too many deceptive synonyms and seemingly equivalent syntactic patterns in English that mean different things in Natural Inform.)