I have been posting about kinds and their specifics, but now I want to ask about kinds of lists. I want a spell book to contain a list of text (spells) that I can add to from a table, and read back to get a list of those spells. The parser is giving me a not-specific-enough error as before, but I don’t know. I create a rule for the very purpose of needing to know what specific item I am reading from.
[Define readable things.]
A readable thing is a kind of thing.
A readable thing has some text called inscription-text.
A readable thing can be read or unread.
A spell book is a kind of readable thing. A spell book has a list of text.
A magical spell book is a kind of spell book.
A clerical spell book is a kind of spell book.
[New READ COMMAND.]
Understand the command "read" as something new.
Understand "read [something]" as reading.
Reading is an action applying to one thing, requiring light.
Carry out reading:
if noun is spell book:
say "Within the contents of the spell book you find these spells:[line break]";
say "Name Cost Notes[line break]";
let L be list of text of spell book;
say "[L]";
otherwise:
say "[inscription-text of noun]";
now noun is read;
[To add a spell to the book]
to learn (spell - text) in (book - spell book):
let spelltbl be Table of Magical Spells;
if book is clerical spell book:
now spelltbl is Table of Clerical Spells;
let L be list of text of book;
add spell to L;
Problem. In the sentence ‘let L be list of text of spell book’, it looks as if you intend ‘list of text of spell book’ to be a property, but ‘a spell book’ is not specific enough about who or what the owner is.
There must be some simple syntax I am missing.
When you just say “spell book”, Inform doesn’t know which specific spell book you mean. In this case, the one you mean is the noun, so say “the noun” instead.
Yes, thank you. That did not give me a parer error. It seems (at least) nuanced to distinguish “noun” from “spell book”, but ok. (Noun is pretty general too.)
Secondly, there was nothing in the book. Didn’t the LEARN rule put something in that list of text?
Oh, here is some code about learning spells.
let myCSB be a random clerical spell book in GenerationSpace;
now player is carrying myCSB;|
learn "Cure Light Wounds" in myCSB;
I revised the code to follow the I7 docs section 16.5 Choosing Rows. All seems like it should work but I get a malformed choose error.
to learn (spell - text) in (book - spell book):
let spelltbl be Table of Magical Spells;
if book is clerical spell book:
now spelltbl is Table of Clerical Spells;
let L be list of text of book;
add spell to L;
say "Trying to put [spell] spell into [book] consulting [spelltbl][line break]";
choose row with a name of spell in spelltbl:
say "I found it!";
say "[current table row]";
[ add name entry to L;
add cost entry to L;
add notes entry to L;
]
Problem. You wrote ‘choose row with a name of spell in spelltbl’: but the punctuation here ‘:’ makes me think this should be a definition of a phrase and it doesn’t begin as it should, with either ‘To’ (e.g. ‘To flood the riverplain:’)…**
A spell book is a kind of readable thing. A spell book has a list of text.
A magical spell book is a kind of spell book.
A clerical spell book is a kind of spell book.
I thought L would become the list of text in the spell book. How do I reference the list of text that already exists in the book?
I think list of test of book is the correct way to reference it, but let is a bit special about how its argument is interpreted, so that might be confusing things. What if you just say add spell to list of text of book?
I think probably what happened is that L was a copy of the spell book’s list, so you added the spell to that copy but never put the copy back in the spell book.
I think you misunderstood… adding to it is a form of editing. I meant you wouldn’t need to worry about this issue in places where you’re just looking at the list.