Inform 7 Home Page / Documentation


§16.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; but if not, note that any existing row selection will be lost, so make use of the row only if the test succeeds.

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

paste.png 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.


arrow-up.png Start of Chapter 16: Tables
arrow-left.png Back to §16.11. Sorting
arrow-right.png Onward to §16.13. Topic columns

***ExampleNoisy Cricket
Implementing liquids that can be mixed, and the components automatically recognized as matching one recipe or another.