Child's Play

An interactive fiction by Stephen Granade (2007) - the Inform 7 source text

Section 1 - Extensions & Workarounds

[Break out of a repeating loop.]
To stop repeating: (- break; -).

[How to find out if a current action is running silently.]
To decide if running silently: (- keep_silent == 1 -). To decide if not running silently: if running silently, decide no; decide yes.

[How to know if a testing command is executing (thanks to JDC)]
To decide if testing is in progress: (- (TestCheck()) -).
To decide if testing is not in progress: (- (~~TestCheck()) -).
Include (-
[ TestCheck ;
#IFDEF TEST_SCENARIOS_EXIST;
if (test_stack-->2 > 1) rtrue;
#ENDIF;
rfalse; ];
-).

[I use randomness in say phrases enough that I want a short form]
To decide if (x - a number) out of (y - a number):
    if a random chance of x in y succeeds, decide yes;
    decide no.

[And similarly a definition for two things being in the same room]
To decide whether (x - a thing) and (y - a thing) are co-located:
    if the location of x is the location of y, decide yes;
    decide no.

To decide whether (x - a thing) and (y - a thing) are not co-located:
    if x and y are co-located, decide no;
    decide yes.

Definition: a thing is present if the location of the player encloses it.

To decide if (x - a thing) is acted upon: if the noun is x or the second noun is x, decide yes; decide no.

To decide if (x - a thing) is not acted upon: if x is acted upon, decide no; decide yes.

[Copy rows from one table to another.]
Include
(-
[ CopyTableRows table1 table2 v0 i j;
    for (i=1: i<=TableRows(table1):i++)
        if (TableRowIsBlank(table1, i)==false) {
            v0 = TableLookUpEntry(table1, 1, i);
            j = TableBlankRow(table2);
            if (TableRowIsBlank(table2, j)==true)
                TableLookUpEntry(table2, 1, j, 1, v0);
        }
    rfalse;
];
-).
To copy rows from (t1 - a table-name) to (t2 - a table-name): (- CopyTableRows({t1}, {t2}); -).

[Remove a room from a backdrop's list of locations. We don't actually delete it -- we write over the value with the value of a placeholder called "MTRoom".]
MTRoom is a room.

Include (-
[ RemoveRoomFromBackdrop R B i k;
    i = B.#found_in;
    for (k=0: k<i/WORDSIZE: k++) {
        if (B.&found_in-->k == R) {
            B.&found_in-->k = (+ MTRoom +);
        }
    }
];
-).
To delete (R - a room) from (B - a backdrop): (- RemoveRoomFromBackdrop({R},{B}); -).

[The printed name of the player is "yourself". That works really well for messages like "You can't take yourself." It fails miserably for things like NPC reactions, where the NPC may be reacting to another NPC or to the player: "Jemison follows [the leader]." So: a workaround "say" phrase.]
To say name of (t - a thing):
    if t is the player begin;
        say "you";
        mark yourself in output;
    otherwise;
        say "[the t]";
    end if.

To say name of (t - a thing) is:
    if t is the player begin;
        say "you are";
        mark yourself in output;
    otherwise;
        say "[the t] is";
    end if.

[A lot of times, I7 is too smart and turns things like aliens' to aliens" when printed. This say statement lets me get around that.]
To say ': say unicode 39.

[Since you can't pass variables defined by "let" or phrase options to another phrase (i.e. I7 has no closures), this hacky global workaround.]
hacky global item is an object that varies.

The source code to Child's Play is licensed under a Creative Commons NonCommercial Sampling Plus 1.0 License.