Adventure Book

version 1/110101 by Edward Griffiths

  • Home page
  • Beginning
  • Previous
  • Next



  • Section 6 -- Reading the Book

    [Special pages provided by the system. Current page and Previous page are for navigating, The Introduction Screen starts us off, and The Last Page gives players an elegant way to end their story, if they so choose.]

    The current page is a page that varies. The current page is The Introduction Screen.

    The previous page is a page that varies. The previous page is The Introduction Screen.

    The Introduction Screen is a special page. "[fixed letter spacing]-- Created using Adventure Book for Inform 7 by Edward Griffiths[line break]
    Based on Adventure Book by Jon Ingold

    Command Summary:[line break]
    LOOK / L Repeat the last page[line break]
    INVENTORY / I Show player inventory[line break]
    SAVE / S Save the game[line break]
    RESTORE / R Restore the game[line break]
    QUIT / Q Quit the game[line break]
    RESTART / X Restart the game[line break]
    HELP / H This text[line break]
    [line break]
    Select options by their number. To use an object, type its name as it appears in the inventory list.[variable letter spacing]".
    A choice called introductionscreenbegin is for The Introduction Screen. "Continue." It triggers The First Page.

    The Last Page is a special page. "X) Restart[line break]R) Restore[line break]Q) Quit".

    ["Looking" displays the text of the current page and the most recently built list of choices.]

    The finish condition is a flag. Pagenames is a thing. Pagenames can be on or off. Pagenames is off.

    Instead of looking:
        read the current page;
        repeat with N running from 1 to the number of filled rows in the Table of Options:
            now the command is the option in row N of the Table of Options;
            let x be the destination of the command;
            if x is unwritten and x is not special and the initial appearance of x is "", say "*** ";
            say "[N]) [The initial appearance of the command][line break]";
                
    To decide if (possibility - a page) is unwritten:
        if possibility is a dead end, decide no;
        if possibility offers something, decide no;
        if possibility is followed by something, decide no;
        decide yes;

    [Here's where all the magic happens. When the system turns to a page, it first sets the values of previous page and current page, reads through the chain of diversions and dead ends, and rebuilds the list of choices based on the page where it finally ended up. Finally, we make the player look so he can see what's going on after all that chaos.]

    To turn to (destination - a page):
        now the previous page is the current page;
        now the current page is the destination;
        read through to the next decision;
        rebuild the list of choices;
        try looking;

    [Simply clear out the list, go through the choices on the current page, and stick in any choices that are allowed by the current game context.]
        
    To rebuild the list of choices:
        repeat through the Table of Options:
            blank out the whole row;
        repeat with possibility running through choices offered by the current page:
            if the possibility is valid and the possibility is not a use:
                choose a blank row in the Table of Options;
                change option entry to the possibility;

    To decide if (possibility - a choice) is valid:
        repeat with x running through flags required by possibility:
            if x is off, decide no;
        repeat with x running through flags which cancel possibility:
            if x is on, decide no;
        decide yes;

    [First, we need to set up a loop that won't end until we've reached the end of the chain of diversions. For every page we encounter, we have to set and clear all applicable flags. If the page ends in a diversion, we print the text for that page and move on to the next one. Note that previous page isn't updated when we change the current page; this is so we can bounce back to it if our chain of diversions takes us to a dead end.

    When we're done diverting, we check to see if we've reached a dead end. If yes, we display the text for our dead end and bounce back to the previous page. Note that we never print the text for the page of the player's final destination; since the list of choices hasn't been rebuilt for the player's new destination, there's nothing meaningful to display yet.]

    To read through to the next decision:
        now the finish condition is off;
        while the finish condition is off:
            run inform code for the current page;
            repeat with gizmo running through flags given by the current page:
                set gizmo;
            repeat with gizmo running through flags removed by the current page:
                clear gizmo;
            if the current page is followed by something:
                read the current page;
                now the current page is the destination of the current page;
            otherwise:
                now the finish condition is on;
        if the current page is a dead end:
            read the current page;
            now the current page is the previous page;

    To read (x - a page):
        if the initial appearance of x is not "", say "[if pagenames is on][the current page][line break][end if][The initial appearance of x][paragraph break]";

    To set (x - a flag):
        if x is not a magic word:
            now x is on;
            if x is an inventory item, now the player is holding x;

    To clear (x - a flag):
        if x is not a magic word:
            now x is off;
            if x is an inventory item, remove x from play;

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

    To change pages to (x - a page):
        now the current page is x;
        run inform code for x;
        
    [And a few final setup details. The game room exists as a concession to the Inform 7 system so that there's a "place" where the player exists while he's reading this book. Magic words are explicitly placed into scope for the wielding action. Finally, we abolish the status line for stylistic reasons.]
        
    There is a room called the game room. The printed name is " ".

    After deciding the scope of the player while wielding:
        repeat with x running through magic words:
            place x in scope;

    Rule for constructing the status line: do nothing.

    Use memory economy.