Pages
Suppose we have a book that the player must consult page-by-page, and we want to be able to accept all of the following input:
One approach would be to write many different understand rules and actions: one action for reading randomly, one for reading a specific page, one for reading the first page, one for reading the previous page, one for reading the next page, and one for reading the last page. But this gets tedious to construct and maintain.
More usefully, we could consider that all of the last four options are essentially the same action at heart: the player is asking to read a page in the book using a name rather than a number, and we will have to perform a minor calculation to discover what the number should be. Here's an implementation using named values to resolve this problem:
page | content |
2 | "dhuma jyotih salila marutam / samnipatah kva meghah / samdes arthah kva patukaranaih / pranibhih prapaniyah" |
13 | "amathesteron pws eipe kai saphesteron" |
50 | "Rrgshilz maplot..." |
Test me with "read from the sinister book / read the book / read the next page / read page 2 / read previous page / g / read the first page / read the last page of the book / read the next page / read 47 in book".
>(Testing.)
>[1] read from the sinister book
You flip the pages randomly and arrive at page 34:
Page 34 appears to be blank.
>[2] read the book
You flip the pages randomly and arrive at page 22:
Page 22 appears to be blank.
>[3] read the next page
(in the sinister book)
Page 23 appears to be blank.
>[4] read page 2
(in the sinister book)
You read: "dhuma jyotih salila marutam / samnipatah kva meghah / samdes arthah kva patukaranaih / pranibhih prapaniyah"
>[5] read previous page
(in the sinister book)
Page 1 appears to be blank.
>[6] g
(in the sinister book)
The page numbering begins with 1.
>[7] read the first page
(in the sinister book)
Page 1 appears to be blank.
>[8] read the last page of the book
You read: "Rrgshilz maplot..."
>[9] read the next page
(in the sinister book)
There are only fifty pages in the book.
>[10] read 47 in book
Your eyes burn; your ears ring. Beneath your gaze, the dreadful sigils writhe, reminding you of that which lies outside the edges of the universe...
*** You have lost your remaining sanity ***