I want to make a spell book, which is a list of text (spell names). This seems to be a simple thing, but I continue to get hung up on details. If the player reads the spell book, the player will see the name, level, and description of the spells contained.
I have this so far:
A readable thing is a kind of thing.
A readable thing can be read.
A spellbook is a kind of readable thing. Understand "spell book" as spellbook.
Description of spellbook is "A thick tome needed for casting spells. Its title letters almost glow.".
A clerical spellbook is a spellbook.
A magical spellbook is a spellbook.
Table of Spells
Spell Level Description
"Healing" 1 "Restores d8+1 HP"
"Magic Missle" 1 "Does d4 damage on target"
"Identify" 2 "Identifies target item"
[To add a new spell to a spellbook.]
To learn text (called newSpell) in list (called spellbook):
add newSpell entry to spellbook;
The rule is executed
now player has a clerical spellbook;
learn "Healing" in clerical spellbook;
I already have the READ command working. My problem comes when (1) trying to define a spellbook as a list (or containing a list); and (2) how to work with it. The TO LEARN rule is causing the problem.
Any help is appreciated.
This gets a little involved, but this shows a possible approach.
Lab is a room.
A thing can be readable.
A spell is a kind of thing.
A spell has a number called level.
A spell has a text called description.
Some spells are defined by the table of magic spells.
A spellbook is a kind of thing.
A spellbook is always readable.
Understand "spell book" as spellbook.
Description of spellbook is "A thick tome needed for casting spells. Its title letters almost glow.".
A clerical spellbook is a spellbook.
A magical spellbook is a spellbook.
A spellbook has a list of spells called contents.
The player carries the clerical spellbook.
The player carries the magical spellbook.
Table of Magic Spells
Spell Level Description
Healing 1 "Restores d8+1 HP"
Magic Missile 1 "Does d4 damage on target"
Identify 2 "Identifies target item"
when play begins: add Identify to the contents of the magical spellbook.
understand the command "read" as something new.
reading is an action applying to one thing.
understand "read [thing]" as reading.
check reading a not readable thing: instead say "[regarding the noun][Those] [aren't] readable.".
carry out reading a spellbook:
if contents of the noun is empty begin;
say "[The noun] is blank.";
else;
say "It contains:[line break]";
repeat with hex running through contents of the noun begin;
say "[hex]: [description of hex][line break]";
end repeat;
end if;
inscribing is an action applying to one visible thing and one touchable thing.
To inscribe is a verb.
understand "inscribe [any spell] in/into/within [spellbook]" as inscribing.
carry out inscribing:
add the noun to the contents of the second noun.
report inscribing: say "[We] [inscribe] [the noun] in [the second noun]."
test me with "read clerical spellbook / read magical spellbook / inscribe magic missile in magical spellbook / read magical spellbook"
An alternative that uses relation instead of a list of spells property:
Lab is a room.
A thing can be readable.
A spellbook is a kind of thing.
A spellbook is always readable.
Understand "spell book" as spellbook.
Description of spellbook is "A thick tome needed for casting spells. Its title letters almost glow.".
A clerical spellbook is a spellbook.
A magical spellbook is a spellbook.
A spell is a kind of thing.
A spell has a number called level.
A spell has a text called description.
Some spells are defined by the table of magic spells.
The player carries the clerical spellbook.
The player carries the magical spellbook.
Table of Magic Spells
Spell Level Description
Healing 1 "Restores d8+1 HP"
Magic Missile 1 "Does d4 damage on target"
Identify 2 "Identifies target item"
Inscription relates a spellbook to various spells.
The verb to be inscribed in means the reversed inscription relation.
Identify is inscribed in the magical spellbook.
understand the command "read" as something new.
reading is an action applying to one thing.
understand "read [thing]" as reading.
check reading a not readable thing: instead say "[regarding the noun][Those] [aren't] readable.".
carry out reading a spellbook:
let l be the list of spells inscribed in the noun;
if l is empty begin;
say "[The noun] is blank.";
else;
say "It contains:[line break]";
repeat with hex running through l begin;
say "[hex]: [description of hex][line break]";
end repeat;
end if;
inscribing is an action applying to one visible thing and one touchable thing.
To inscribe is a verb.
understand "inscribe [any spell] in/into/within [spellbook]" as inscribing.
carry out inscribing:
now the noun is inscribed in the second noun.
report inscribing: say "[We] [inscribe] [the noun] in [the second noun]."
test me with "read clerical spellbook / read magical spellbook / inscribe magic missile in magical spellbook / read magical spellbook"
Involved, indeed! I just want to know how to create a list as a thing.
Will Spellbook is a list of text. work?
If so, I can add lines of text to the spellbook.
If not, what does?
Apparently, a list cannot be created in declarative space, only operative space. That seems to be a major limitation of Inform.
Iām not entirely clear on what you mean by āin declarative spaceā (do you mean compile time rather than run time?), but you can declare a list as a global variable:
These example statements all happen within some rule.
I want to create a thing (a book) that is a list of text.
I can say A book is a thing but I canāt say A book is a list of text for some reason without getting a parsing error.
How do I create a book that is a list of text?
Like @kamineko said above: A book is a list of text that varies.
When I try to compile A book is a list of text. it tells me what the problem is, and suggests that exact solution:
Problem. The sentence āA book is a list of textā (line 5) reads to me as if ābookā refers to something I should create as brand new - a list of texts. But that canāt be right, because this is a kind of value where I canāt simply invent new values. (Just as the numbers are ā¦, 1, 2, 3, ⦠and I canāt invent a new one called āSusanā.)
Perhaps you wanted not to invent a constant but to make a variable - that is, to give a name for a value which will change during play. If so, try something like āThe bonus is a number which variesā.
But that might not be what you want, since that would mean the book couldnāt exist in the game world - itās just a list, not a thing, and a list canāt be in the game world any more than a number can. You canāt say A toilet is a number that varies. A toilet is in the restroom. either. Numbers and lists are both values, not things.
But you could say a simpler version of what @Zed suggested above (his code is involved, but itās worth reading through to understand how these definitions work):
A book is a kind of thing. A book has a list of text called the spells.
(Here the āthat variesā is implied - if you try to put it in, Inform tells you that you should remove it.)