![]() | 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.
| ![]() A treatment of money which keeps track of how much the player has on him, and a BUY command which lets him go shopping. |
|
| ![]() ![]() An OFFER price FOR command, allowing the player to bargain with a flexible seller. |
|
| ![]() ![]() ![]() Using the liquid implementation demonstrated in Lemonade for putting out fires. |
|
| ![]() ![]() ![]() 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 |