Adventure Book

version 1/110101 by Edward Griffiths

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter: Advanced Features

    Section: Setting Conditions

    The advantage of a computer program over a traditional Choose Your Own Adventure story is that the computer can remember what has already happened and adapt what happens next based on that history. Adventure Book lets you use on or off markers called flags to keep track of what has happened and what the player can do.

    Flags don't need to be declared in any special way. If you create a page that turns a flag on or off, Inform will automatically create that flag for you. However, a flag can be created with a sentence like "[The flag's name] is a flag." For example:

        TheReadingLampIsOn is a flag.

    Most flags begin the game in the off position. To set a flag to the "on" position, add the line "It gives [the flag's name]." just after the page's description and before the list of choices:

        Turning on the Reading Lamp is a page.
        "You turn the reading lamp on."
        It gives TheReadingLampIsOn.

    Now, whenever Turning on the Reading Lamp is read, the flag called TheReadingLampIsOn will be turned on.

    To return a flag to the off position, add the line "It removes [the flag's name]." just after the page's description:

        Turning off the Reading Lamp is a page:
        "You turn the reading lamp off."
        It removes TheReadingLampIsOn.

    Any number of "It gives ..." and "It removes..." lines can be added to a page, just as long as they're all listed before defining the choices (or "It is a dead end." or "It is followed by..." statements) for that page. For example:

        Confusing Mess is a page:
        "Goodness! A lot has happened on this page!"
        It gives TheDuckHasBeenSeen. It removes TheShirtIsWhite. It gives LoudMusicIsPlaying. It is a dead end.

    Flags affect the game by changing which options are allowed on a given page. Here is a choice to look at a bookshelf, but only if the reading lamp is turned on.

        In the Library is a page.
        "You are in your cozy library, surrounded by your favorite books."
        A choice called IntheLibraryA is for In the Library. "Look at the bookshelf." It triggers Examine Bookshelf. It requires TheReadingLampIsOn.

    Adding "It requires [flag name]." to the description of a choice prevents it from being printed if the flag is turned off. In this case, the player will never be able to select an option to look at the bookshelf unless the flag TheReadingLampIsOn has been turned on.

    Adding "It is cancelled by [flag name]." to the description of a choice prevents it from being printed if the flag is turned on. This can be used to create choices like this:

        In the Library is a page.
        "You are in your cozy library, surrounded by your favorite books."
        A choice called IntheLibraryA is for In the Library. "Look at the bookshelf." It triggers Examine Bookshelf. It requires TheReadingLampIsOn.
        A choice called IntheLibraryB is for In the Library. "Look at the bookshelf." It triggers Too Dark. It is cancelled by TheReadingLampIsOn.

    This would give the player a choice called "Look at the bookshelf." no matter whether the lamp is on or not, but where the player goes when he selects it depends on the state of the lamp.

    Any number of "It requires..." or "It is cancelled by..." statements can be added to the end of a choice's description. If any one of them would prevent a choice from being displayed, the choice is not printed.

        A choice called ByThePondA is for By The Pond. "Look at the ducks." It triggers Examine Ducks. It requires TheDucksAreByThePond. It is cancelled by TheStreetLightIsBroken.

    In this case, "Look at the ducks." would only be printed if TheDucksAreByThePond is on and TheStreetLightIsBroken is off.

    Note for advanced Inform users: You can alter the text printed in a page using the techniques described in Chapter 5.5 of Writing with Inform. The syntax for the conditions is simply "[if (the name of the flag) is (on or off)]".