10.3. Dispensers and Supplies of Small Objects

| Chapter 10: Physics: Substances, Ropes, Energy and Weight |

| 10.3. Dispensers and Supplies of Small Objects

A slightly tricky situation arises in IF when we want to offer the player a simulation of a near-infinite supply of something: a napkin dispenser from which he can keep taking more napkins, or an infinite selection of pebbles on a beach, or something of that nature.

One approach is simply to limit the number of items the player is allowed to pick up at a time, while maintaining the fiction that there are more of these items in existence than the player is allowed to interact with. Extra Supplies demonstrates this.

The task becomes harder if we do want to let the player have as many napkins as he wants. In some languages, it is possible to generate new objects on the fly after the game has begun (called "dynamic object creation"), and something like this is possible if we are compiling for Glulx. (See the Inform extensions site for examples.) Usually, though, it is less complicated and almost as effective simply to have a very large supply of existing objects, which are moved in and out of play as the player needs them. Pizza Prince demonstrates how to do this with slices of pizza.

See Ropes for an example involving divisible pieces of string, which relies on similar techniques

124
| Example Extra Supplies A supply of red pens from which the player can take another pen only if he doesn't already have one somewhere in the game world. |
WI

Suppose we have a supply closet in our game from which the player is allowed to take red pens. To keep modeling simple, we only allow him to have one in play at a time, and we test this by seeing whether the red pen is "off-stage" before moving it to his possession. This approach might seem no different from having a single red pen sitting in the closet, but it may be preferable, for two reasons. First, it's not very plausible for a supply closet to contain nothing but a single red pen (well, assuming a well-regulated supplier, anyway); and second, it gives the player a way to get a new red pen should the original be destroyed in a tragic handwriting accident. "Extra Supplies" The Supply Closet is a room. A supply of red pens is in the Supply Closet. Understand "pen" as the supply of red pens when the red pen is not visible. There is a red pen. Instead of taking the supply of red pens: if the red pen is off-stage: move the red pen to the player; say "You help yourself to a fresh red pen."; otherwise: say "You're only allowed one pen at a time. The department secretary is very strict." South of the Supply Closet is the Furnace Room. The incinerator is a thing in the Furnace Room. It is a container. "The incinerator is here, working full blast." After inserting something into the incinerator: remove the noun from play; say "A fiery blast consumes [the noun]!" Test me with "get pen / i / get pen / get supply / s / put pen in incinerator / n / get pen".

364
| Example Pizza Prince Providing a pizza buffet from which the player can take as many pieces as he wants. |
WI

Previous | Contents | Next