15.12. Listed in...

| Chapter 15: Tables |

| 15.12. Listed in...

Tables are especially useful for combining a run of basically similar rules in a simple and concise way. The "listed in" condition, as in

> if the newfound object is an item listed in the Table of Treasures...

looks through a given table (here "table of treasures"), in a given column ("item"), to see if a given value is present ("the newfound object"). If this is successful, the row where it was found is automatically chosen.

We can similarly use "... listed in ..." in a description used when specifying an action. Thus:

> After taking an item listed in the Table of Treasures:
> if there is no time entry:
> now the time entry is the time of day;
> increase the score by the value entry;
> say "Taken!"

This assumes a table in the following shape:

> Table of Treasures

> Item | Value | Time
> brooch | 5 | a time
> tiara | 8 | --
> coronet | 10 | --

In effect the table has allowed us to combine three very similar rules into one. The time column records the first time at which the item has been picked up, which starts out blank since at the start of play it has never been picked up. This enables us to award the appropriate number of points on the first occasion only.

265
| Example Noisy Cricket Implementing liquids that can be mixed, and the components automatically recognized as matching one recipe or another. |
RB

Previous | Contents | Next