version 2 by Jim Aikin
Section: Using Spellcasting.
To add our own spells to a game, we need to do a few things.
First, we create Table of Spells (continued). The Table of Spells (continued) should have the following headings: Spell, Output, Directed Output, Description.
Put new spell words into the Spell column. The other three columns should contain double-quoted text. The Output column should contain the default text that will print when the player types the name of the spell as a bare command ("shazam") or uses the "cast" verb ("cast shazam"). The Directed Output column should contain the default text that will print when the player casts the spell at an object in the game using the format "shazam the X" or "cast shazam at X". In most cases these defaults won't be needed, because the handling of spell-casting will be under the control of instead rules; but writing catch-all default messages is good coding style. The Description column should contain a brief description of the spell, which will be printed (after the spell has been learned) in response to the "spells" command.
After entering a new spell in the Table of Spells (continued), declare the name of the spell as a magic-spell. A magic-spell is a kind of backdrop, which is convenient as we want it to be present in the room no matter where the player is. Because Inform can't put kinds in locations, we have to make each of our magic-spells everywhere, like this:
shazam is a magic-spell. It is everywhere.
Alternatively, we might want to define a region in which the shazam spell will operate, and confine the backdrop to that region. If we do this, however, the spell will not be in scope when the player is not in that region, which will cause a spell the player has learned to erroneously appear unlearned when the player tries to cast it in the wrong place. A better solution is to edit the Output or Directed Output message of the spell in a way that depends on the player's location.
This is easily done using "To say" code. In the Output column, the text should read something like "[shazam-cast]". We could then write code like this:
To say shazam-cast:
if the player is in the Arboretum...
Because magic-spells are unlearned by default, the next step in coding is to specify the manner in which the new spells can be learned.
Finally, we write our own Instead rules for casting specific spells, either without an object ("shazam") or at specific objects ("shazam the X").
We can also, if desired, substitute our own messages for the extension's error messages no-spells-learned, not-a-spell, unknown-spell, unlearned-spell, and cant-see-any-such:
To say not-a-spell:
say "What are you gibbering about now?"
If a game uses some other message than "You can't see any such thing" in response to references to things that are invisible or nonexistent, it's a good idea to substitute the new message for cant-see-any-such.