Spellcasting

version 2 by Jim Aikin

  • Home page
  • Beginning
  • Previous



  • Example: ** The Sorcerer's Apprentice - Some new spells that can be learned from a dusty old book.

        "The Sorcerer's Apprentice"

        Include Spellcasting by Jim Aikin.

        The Wizard's Inner Chamber is a room. "This tall, dusty room is littered with magical apparatus. Inasmuch as you're only a lowly apprentice, you have no idea what most of it does."

        The big round beach ball is in the Chamber. The description is "Big and round and bright red and yellow." Understand "bright", "red", and "yellow" as the beach ball.

        A thing can be consultable. A thing is usually not consultable.

        The dusty old book is in the Chamber. "The wizard seems to have left his book of magic spells lying out in plain view!" The description is "It's a very dusty old book. You recall seeing the wizard look up various spells in the book, including frotz, nitfol, and gnusto." The dusty old book is consultable.
        
        Researching it in is an action applying to two things. Understand "research [something] in [something]" and "look up [something] in [something]" as researching it in.

    The check rule for researching it in will reject everything, because we're going to use instead rules for researching.

         Check researching it in:
            if the second noun is not consultable:
                say "[The second noun] [if the second noun is plural-named]are[otherwise]is[end if] not useful for researching things.";
            otherwise if the noun is not a magic-spell:
                say "You leaf through the book, but find nothing on that subject.";
            otherwise:
                say "Hmm ... that page of the book seems to have been torn out."
            
        Carry out researching it in:
            say "This message should never print."

        Instead of consulting the book about something:
            say "So many words ... it's all just a blur."

    The consulting action, which is part of the Inform library, can be used only with topics, not with objects. Since we're making the spells objects, this action won't work with them. Thus the new action, researching it in.

    When the researching it in action is being invoked, its instead rule will supersede the default instead rule contained in the extension, which prohibits any reference at all to the spell objects, other than the actions involved in casting the spells.

         Instead of researching a magic-spell in the book:
            say "Hmm ... that page of the book seems to have been torn out."
        
        Instead of researching frotz in the book:
            if frotz is learned:
                say "You've already learned the frotz spell from the book.";
            otherwise:
                now frotz is learned;
                say "You find the page in the book that describes the frotz spell, and commit the spell to memory."
            
        Instead of researching nitfol in the book:
            if nitfol is learned:
                say "You've already learned the nitfol spell from the book.";
            otherwise:
                now nitfol is learned;
                say "You find the page in the book that describes the nitfol spell, and commit the spell to memory."

        Table of Spells (continued)
      Spell  Output  Directed Output  Description  
      frotz  "You cast the frotz spell, but nothing happens."  "You cast frotz at [the second noun], but nothing happens."  "The frotz spell causes spherical objects to quiver."  
      gnusto  "You cast the gnusto spell, but nothing happens."  "You cast gnusto at [the second noun], but nothing happens."  "The gnusto spell causes great gusts of wind."  
      nitfol  "You cast the nitfol spell, but nothing happens."  "You cast nitfol at [the second noun], but nothing happens."  "The nitfol spell does something completely different."  

        frotz is a magic-spell. It is everywhere.
        gnusto is a magic-spell. It is everywhere.
        nitfol is a magic-spell. It is everywhere.

        Instead of casting frotz at the beach ball:
            if frotz is not learned:
                say "[unlearned-spell]";
            otherwise if the beach ball is held:
                say "The beach ball quivers vigorously for a moment.";
            otherwise:
                say "The ball bounces several times and then comes to rest."
            
        Test learning with "spells / look up nitfol in book / spells / nitfol / nitfol the ball".

        Test casting with "cast shazam at ball / cast frotz at ball / look up frotz in book / cast frotz at ball / take ball / frotz ball".

        Test errors with "x frotz / take nitfol / frotz book / gnusto book / look up gnusto in book / frotz desk".

        Test me with "test learning / test casting / test errors".