Question about Tables

I’m trying to create a way where the player could learn a language by studying a book, which would then be used to translate various documents found later on.

I was able to do it with an exhaustive list of check/carry out routines, but I thought it would be simpler to do by consulting a table which could include all the different languages contained in books that the player can find and study. Below follows my attempt which won’t compile…

[code]The Library is a room.

A language is a kind of thing. A language can be learned or unlearned. A language is usually unlearned.

Latin is a language.

A dusty book is in the Library. The description is “[if latin is unlearned]Difficult to comprehend.[otherwise]Readable now.”

Understand “study [text]” as studying.

Studying is an action applying to one language.

Carry out studying:
say “Nothing comes to mind.”.

Instead of studying a language listed in the Table of Books:
say “[response entry][paragraph break]”.

Table of Books
language response
“latin” “[if the player is holding the dusty book]You study the latin text.[now the language is learned][otherwise]There’s nothing here to study[end if]?” [/code]

I’m wondering if there’s an easy fix to this? – Or am I way off base?

Thanks again in advance for any help or tips to try out!

You’re pretty close - but here’s a couple of your problems:

  1. Action definitions can’t take specific kinds - and that’s a good thing, because it would just make the parser errors more confusing. Use a check rule with your action to limit the kinds of things the player can act on.

  2. If you want an action on things that aren’t present, you have to define it as an action “one one visible thing.”

  3. Your Table of Books has texts, not languages, in the language column. Get rid of the quotes around “latin” and it will work.

  4. you can’t put “now…” phrases inside text. If you don’t want to do that in a carry out rule, you’ll have to create a say phrase to set that up.

I’ve also replaced your carry out rule with a check rule, because it’s best not to say anything in a carry out rule. Having taken care of that, your Instead rule can be split up into check, carry out and report rules. However, I’m not sure what your intended behavior is for multiple languages. Are they all learned from the same book, or is the language always learned from the same book it’s written in? To implement the last two cases, you’ll need to add a column to your table, use some properties of languages or books, or use relations.

You don’t really need tables at all for this. You could, for example, set up a relation between languages and books, and give each language a “learning” text property that will be printed by the report studying rule.

A possible solution is below:

[code]The Library is a room.

A language is a kind of thing. A language can be learned or unlearned.

A dusty book is in the Library. The description is “[if latin is unlearned]Difficult to comprehend.[otherwise]Readable now.”

Latin is a language.

Understand “study [any thing]” as studying.

Studying is an action applying to one visible thing.

Check studying something that is not a language:
say “Studying a language would be more productive.” instead;

Check studying when the noun is not a language listed in the Table of Books:
say “You don’t know what book would teach you [the noun].” instead.

Check studying:
Choose row with language of the noun in Table of Books;
if the tutorial entry is not held, say “You need to be holding [the tutorial entry] to study [the noun].” instead;

Carry out studying:
now the noun is learned.

Report studying:
choose row with language of the noun in Table of Books;
say “[response entry][paragraph break]”.

Table of Books
language tutorial response
latin dusty book “You study the latin text.” [/code]

Turns out it wasn’t nearly as easy as I expected…!

Just to add to Capmikee’s observations, even if you had created an action applying to one thing, your grammar line (“Understand “study [text]” as studying”) doesn’t match. The bracketed token has to be the same kind as the action is looking for – in this case a thing, not text.

Below is an alternate example of how you could go about this. I wasn’t sure if you wanted the player to study a particular book or a language, so I coded up something that does both. However, there are really only two primary differences between my method and Capmikee’s.

First, I made languages a kind of value (KOV) rather than a kind of thing. When things are referred to in commands, they need to be in scope. (The combined use of “visible” and “any thing” is one way of doing this.) KOVs don’t have this restriction; they can be referred to (in commands which recognize them) at any time. Also, you can (usually) assign properties to KOVs – like learned / unlearned – so you don’t lose anything.

The second difference involves the table. I agree with Cap that you don’t really need tables (I probably wouldn’t have approached it that way), but some authors like the way tables organize info and it’s certainly a viable choice. The thing to note is that there are two very distinct ways of using tables in I7. One is the way you’re using them now: looking up entries and cross - referencing them. The other is to use a table to actually define (create) objects or values (see ch. 15.16 of the docs). The downside to this method is that tables used this way can’t really be messed with (sorted, changed, in some cases even accessed) in - game. The upside is that you usually don’t need to; Inform automatically assigns the other columns as properties of the thing being defined.

In the example below, I’ve created a book “kind” and defined the individual books in a table with headings (language, unlearned description, learned description). I don’t have to say “A book has a language” because Inform is able to infer from the table that books have that property. More importantly, if I ever need to find the value of that property later, I just have to say “language of the dusty book,” rather than “choose the row corresponding to blah blah blah…”

Sorry if this explanation seem convoluted or complex. The code is actually pretty simple. :slight_smile: [code]Section - Languages

A language is a kind of value.
The languages are Latin, Greek, English and Martian.
A language can be learned or unlearned. [<- unlearned is already the default]
English is learned.

Section - Books

A book is a kind of thing. Some books are defined by the Table of Fancy Books.
The description of a book is usually “[The item described] [if the language of the item described is unlearned][unlearned description].[otherwise][learned description].”

Table of Fancy Books
book language unlearned description learned description
a dusty book latin “is difficult to comprehend” “is readable but boring”
Time Magazine English “is filled with pictures” “is filled with ads”
an old scroll Greek “has letters like on a frat house” “tells the tale of Odysseus”

Section - Studying Action

Studying is an action applying to one thing.
Understand “study [something]” or "learn [something]"as studying.

Check studying:
if the noun is not a book,
say “Nothing comes to mind.” instead.

Check studying:
if the language of the noun is learned,
say “Since you already know [language of the noun], you are able to determine that [the noun] [learned description].” instead.

Carry out studying:
now the language of the noun is learned.

Report studying:
say “You study [the noun] and find you are now able to read [language of the noun].”

Section - Learning Action

Learning is an action applying to one language.
Understand “learn [language]” or “study [language]” as learning.
The learning action has an object called the studied book.

Setting action variables for learning:
repeat with B running through books in the location:
if the language of B is the language understood:
now the studied book is B.

Check learning:
if the language understood is learned,
say “You already know [language understood].” instead.

Check learning:
if the studied book is nothing,
say “You don’t see any books here that look like [language understood].” instead.

Carry out learning:
try studying the studied book instead.

Section - Scenario

The Library is a room.
The dusty book, Time Magazine, and the old scroll are in the Library.
A football is in the Library.

test me with “study football / x dusty / learn martian / study english / learn latin / x dusty book / x time / study it / x scroll / study it / read it / learn greek / study scroll / learn it”.[/code]
P.S. Remember to watch your tabs when cutting / pasting the above. I think the only tab-sensitive rule is the “Setting action variables for learning” rule.

Edit: In the description of the book I originally used “the noun” which works in this case, but changed it to “item described” which is safer and syntactically correct.