Adventure Book

version 1/110101 by Edward Griffiths

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Running Inform Code

    Whenever a page is triggered (except when it's returned to as a result of a dead end statement), the system invokes a phrase called "run inform code for [page name]". This is the default behavior:

        To run inform code for (x - a page):
            do nothing;

    This doesn't do anything interesting on its own. Rather, it's an entry point that allows the author to sneak in a snippet of Inform code that's performed in special circumstances.

    For example, let's say that we want to have a choice that could lead to one of two pages, chosen at random. We could define a special case for "run inform code for..." that randomizes the player's destination when that choice is invoked:

        "Opening Kickoff" by Edward Griffiths
        
        Include Adventure Book by Edward Griffiths
        
        The First Page is a page.
        "You toss the coin up in the air...".
        A choice called tfpa is for The First Page. "Which way did it land?" It triggers Landing.
        
        Landing is a special page.
        
        To run inform code for (x - Landing):
            if a random chance of 1 in 2 succeeds:
                change pages to Heads;
            otherwise:
                change pages to Tails;
        
        Heads is a page.
        "Heads!"
        It is followed by Reflip.
        
        Tails is a page.
        "Tails!"
        It is followed by Reflip.
        
        Reflip is a page.
        "Care to try it again?"
        A choice called reflipa is for Reflip. "Sure!" It triggers Landing.

    The phrase "change pages to [page name]" is used in "run inform code for..." definitions when we want to trigger a different page as a result of what happened in our program. It ensures that any inform code for the new page will be run as the game continues forward. It is bad practice to use "turn to..." statements in your "run inform code for..." definitions because it can lead to recursion and unexpected effects.

    Inform code extensions can give an Adventure Book a whole new flavor. See the example "Combat System" for a demonstration.