| Chapter 14: Units |

| 14.12. Arithmetic with units

Inform allows us to perform arithmetic on units only where that would make sense, and it keeps track of the results. For instance,

> The Weighbridge is a room. "A sign declares that the maximum load is [100kg multiplied by 3]."

...will produce the text "A sign declares that the maximum load is 300kg." Here Inform knows that it makes sense to multiply a weight by 3, and that the result will be a weight. Similarly, Inform allows us to add and subtract weights, and several different forms of division are allowed:

> The blackboard is in the Weighbridge. "A blackboard propped against one wall reads: '122 / 10 is [122 divided by 10] remainder [remainder after dividing 122 by 10]; but 122kg / 10kg is [122kg divided by 10kg] remainder [remainder after dividing 122kg by 10kg]; and 122kg / 10 is [122kg divided by 10] remainder [remainder after dividing 122kg by 10].'"

When we visit the Weighbridge, we find:

> A blackboard propped against one wall reads: "122 / 10 is 12 remainder 2; but 122kg / 10kg is 12 remainder 2kg; and 122kg / 10 is 12kg remainder 2kg."

Whereas we are not allowed to divide 122 by 10kg: that would make no sense, since 122 is a number and not made up of kilograms. Inform will produce a problem message if we try.

200
| Example Frozen Assets A treatment of money which keeps track of how much the player has on him, and a BUY command which lets him go shopping.

In our brave new world, everything will have a price, so we had better spell this out. "Frozen Assets" Price is a kind of value. $10.99 specifies a price. A thing has a price. The price of a thing is usually $0.00. After examining something for sale, say "It can be yours for [the price of the noun]." Now we assume a simple shopping model in which the player can't take anything without paying for it. Definition: a thing is free if the price of it is $0.00. Definition: a thing is for sale if it is not free. Instead of taking something for sale: say "You'll have to pay for that." Before buying something for sale when the money is not in the wallet: say "You're broke." instead. Before buying something for sale when the money is free: say "You're broke." instead. Before buying something for sale when the price of the money is less than the price of the noun: say "Your funds do not run to the price of [the noun]." instead. Instead of buying something: change price of the money to the price of the money minus the price of the noun; say "You fork over [the price of the noun] for [the noun], leaving yourself with [the price of the money]."; if the money is free, remove the money from play; change the price of the noun to $0.00; now the player is carrying the noun. The player's money object is going to be a bit unusual, because it has value but cannot itself be bought. The player carries a wallet. The wallet contains money. The price of the money is $4.50. The printed name of the money is "[price of the money] in cash". Understand "cash" as the money. Instead of taking the money: say "Best to leave it alone until you need to buy something." Instead of buying something free: say "[The noun] is yours already." Instead of buying the money: say "The money belongs to you; you buy things with it." Now we just need something to buy. The Dessert Parlor is a room. "An underlit, over-crowded room campily furnished with a lot of gilt-frame mirrors and twinkle lights: it is essentially a brothel of food. The service is slow at best, and on Saturday nights glacial. However. The wares on display more than make up for these trivial inconveniences." The vanilla ice cream is an edible thing in the Parlor. The price of the ice cream is $2.45. The description is "In the scale of ice creams, you recognize this as a very inferior vanilla because it has no adjectives in the title." The raspberry tart is an edible thing in the Parlor. The price of the tart is $4.50. The description is "An almond-laced shell packed with raspberries-under-glaze." The syllabub is an edible thing in the Parlor. The price of the syllabub is $4.25. The description is "Whipped cream, alcohol, and lime juice, a substance without any redeeming food value whatever." The espresso cake is an edible thing in the Parlor. The price of the espresso cake is $5.50. The description is "A lethal wedge of purest blackness." Test me with "inventory / examine syllabub / get syllabub / buy syllabub / drop it / get it / buy raspberry tart". Implementing caloric units for this scenario is left as an exercise for the reader.

201
| Example Money for Nothing An OFFER price FOR command, allowing the player to bargain with a flexible seller.

202
| Example Lemonade Containers for liquid which keep track of how much liquid they are holding and of what kind, and allow quantities to be moved from one container to another.

Previous | Contents | Next