I7 - Changing descriptions with tables looked up with topics

I am trying to implement a system in which the player can choose a book from a shelf and depending on what topic they call, changes the name and description of the book that they receive. I want to do it this way so I don’t have there be 100+ items in the room.

So the borrowing action (obviously adding synonyms and constraints of use etc.) would look something like this:

[code]The library is a room.

Borrowing is an action applying to a topic. Understand “borrow [text]” as borrowing.

Tome is in the library.

Table of Books
Topic Title Description
“Pride & Prejudice” “Pride & Prejudice” “A witty tale of manners and mistakes in Edwardian high society.”
"Beginners’ Aviation " “Beginners’ Aviation” “What goes up, apparently, doesn’t need to come down straight away.”
“The Prince” “The Prince” “Is it better to be feared or loved?”

Carry out borrowing a topic listed in the table of books:
now the tome is held by the player;
now the description of tome is “[description entry]”;
now the printed name of tome is “[title entry]”.

Report borrowing a topic listed in the table of books:
say “You decide to check out [printed name of tome].”
[/code]

Now, the above doesn’t work but I’m not entirely sure why. When it calls the topic, I can get it to say any of the entries from the topic line. This works fine:

Carry out borrowing a topic listed in the table of books: say "You get [title entry]."

But I can’t seem to use the entries associated with the topics in a more productive way. Every time I deal with topics and text snippets and indexed text it’s a massive headache. Anyone got any insight here?

EDIT:

Ach. I’m beginning to think it’ll be easier to create a whole heap of books defined by the table (like the jersey example in the documentation). Are there performance issues if you have hundreds of items in a room? Or could I call them up from off-stage with a topic?

[code]The library is a room.

Borrowing is an action applying to a topic. Understand “borrow [text]” as borrowing.

Tome is in the library.

Table of Books
Topic Title Description
“pride & prejudice” or “pride” or “prejudice” or “pride and prejudice” “Pride & Prejudice” “A witty tale of manners and mistakes in Edwardian high society.”
“beginners aviation” or “beginners” or “aviation” “Beginners[’] Aviation” “What goes up, apparently, doesn’t need to come down straight away.”
“the prince” or “prince” “The Prince” “Is it better to be feared or loved?”

Check borrowing:
repeat through table of books:
if the topic understood matches the topic entry:
now the tome is held by the player;
now description of tome is description entry;
now printed name of tome is title entry;
say “You decide to check out [printed name of tome].”;
rule succeeds;
say “That book isn’t in the library.”;
rule fails.[/code]

-Wade

My code works, though I’ve written it in my style where I just do everything at the check stage. Just rearrange it slightly to your taste.

I’d like to be able to explain why my method works and what you’ve done doesn’t, but even though I broadly understand (mostly from experience), I’m having trouble doing so. Uh, it’s embarrassing. Topics are weird. Someone else will probably explain.

What I can add is that you’ll need to manually specify alternative shorter titles for the books with ‘or’ phrases, the way I have here, otherwise people would have to type ‘pride & prejudice’ exactly to get that book. When you see that topic entries can have these ‘ors’ defining them, I think that helps to show how they’re different to other kinds of data in tables.

-Wade

EDIT PS - While I fixed the displayed apostrophe in ‘Beginners’ aviation’, I unnecessarily erased it from the topic version of the book title. Either way, you’ll probably want a topic ‘or’ that omits it.

I’m not positive about this, but I think that when you write something like:

now the description of the clock is "The clock says '[time of day]."

Then the effect is just as if you had written this in your initial assertions:

The description of the clock is "The clock says '[time of day]."

Which means that the description of the clock is going to contain a call to “time of day”; it’ll change when the time of day changes.

So when you write:

now the description of tome is "[description entry]";

it tries to make the description of the tome contain a call to “[description entry]”. I don’t know exactly what the results this are, because the under-the-hood* representation of choosing rows in a table is a bit weird in a way I don’t understand at all, but it’s not good.

Wade’s solution (if I’m right) avoids this by writing “now description of tome is description entry;” which doesn’t contain that text substitution. You might try your original code without the quotes. If you wanted to do something a bit more complicated like have your book be “book called ‘title’” I think you could cast everything to indexed text before assigning it, and that’ll make it sticky, like this:

let T be indexed text; now T is "book called '[title entry]'"; now the printed name of the tome is T.

Unsure about this, though, and I haven’t tested it at all.

*Or bonnet, I suppose.

Looks like matt’s right about Joey’s original code working if you just remove the text substitutions. So you don’t need to do my manual repeat through the table after all. I.E. Just change the carry out to:

Carry out borrowing a topic listed in the table of books: now the tome is held by the player; now the description of tome is description entry; now the printed name of tome is title entry.

-Wade

Well that was simpler than anticipated! Thanks a bundle to both of you. I’ll check this all when I get home later. My first inclination is always to want to achieve everything through bracketed text substitutions so it’s not surprising that I didn’t try Matt’s more obvious solution.

I know this isn’t relevant to the original question, but in the spirit of creating the best possible product, I’d like to mention that Pride and Prejudice is set in the Regency period, not Edwardian.

Hah good spot. I just made up the books for the example, they’re not representative of game content.

Oh! I just realised: is there a way of dynamically creating synonyms for objects? Otherwise this solution isn’t going to be very helpful.

In general, I think, it is a complete mess.

However, in this case, since you’re going to be trying to match a topic, you can just match that topic. I can’t think of a way to dynamically add a topic to the understand rules, but you can use after reading a command to just bloop through and replace the topic with the word “tome”:

[code]The library is a room.

Borrowing is an action applying to a topic. Understand “borrow [text]” as borrowing.

Tome is in the library.

Table of Books
Topic Title Description
“Pride & Prejudice” “Pride & Prejudice” “A witty tale of manners and mistakes in Edwardian high society.”
"Beginners’ Aviation " “Beginners’ Aviation” “What goes up, apparently, doesn’t need to come down straight away.”
“The Prince” “The Prince” “Is it better to be feared or loved?”

Carry out borrowing a topic listed in the table of books:
now the tome is held by the player;
now the description of tome is the description entry;
now the printed name of tome is the title entry.

Report borrowing a topic listed in the table of books:
say “You decide to check out [printed name of tome].”

After reading a command when the printed name of tome is a title listed in the table of books:
let T be text;
now T is the printed name of tome;
choose a row with a title of T in the table of books;
if the player’s command includes the topic entry:
replace the matched text with “tome”.[/code]

(I’m very proud to have got that working at all; and it is really annoying that when you’re matching the player’s command to a topic you say “matches” and “includes” but when you’re matching regular expressions you say “exactly matches the text” and “matches the text.” I was trying to use “matches the topic entry” for the longest time.)

Another thing you could do, if you don’t want to create hundreds of objects, is create a table that defines values that you assign to tome (starting with “Title is a kind of value. The titles are defined by the table of titles.”) Then you could define the borrowing command as applying to one title and use “Understand the title property as describing the tome.” I think this would also get you that proper subsets of the the title would refer to it (you could have “x pride” for pride & prejudice) but I’m not sure.

For purposes here, this should cover what you need:

The tome has some text called nickname. Understand the nickname property as describing the tome.

and change the nickname as appropriate.

You can also do conditional understands, if that makes more sense:

Understand "useless" as the tome when The Illiterati Strike Back is happening.

Neither of these are very dynamic, because they don’t allow an indefinite number of synonyms to be added - but it should be more than sufficient for your purposes.