Child's Play

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

Section 2 - Height Checking Rules

[Height Reachability Rules determine whether or not something is reachable due to height restrictions. This rulebooks is called by a "before" rule. Success means the action's okay to continue. Failure means the action should be stopped. If a height reachability rule ends in failure, it should print out why the failure occurred.]

[In theory I could use reaching inside/reaching outside rules, but heights don't necessarily depend on things being inside or outside other things.]

Height Reachability Rules is a rulebook. The height reachability rules have outcomes stop action processing (failure), continue action processing (success), and no decision (no outcome - default).

[Since rules don't have access to rulebook variables in their when/while clauses -- and, in fact, don't have access to e.g. "actor" except inside the rules themselves, I have use global variables.]

[The actor whose reachability we're testing.
N.B. this isn't re-entrant.]
The reaching actor is a person that varies.

[The noun to be height-tested. Also not re-entrant.]
The reaching object is an object that varies.

[It turns out a lot of built-in talking actions require a touchable actor, so fix that oversight.]
A height reachability rule when the current action is being talkative (this is the height-ignoring actions rule):
    continue action processing.

[Getting things held by other people.]
A height reachability rule (this is the objects held by other people rule):
    if the reaching object is enclosed by a parent person (called p) begin;
        if the reaching actor is not enclosed by p begin;
            if the reaching actor is the player, say "[P] has [the reaching object] and so you can't reach it.";
            stop action processing;
        end if;
    end if.

[These next two rules aren't phrased as e.g. "A height reachability rule when the noun is not nothing" so that they're near the bottom of the rulebook.]
A height reachability rule (this is the standard height checking rule):
    if the reaching object is reachable by the reaching actor, continue action processing;
    if the reaching actor is the player, say out-of-reach message for the reaching object;
    stop action processing.

[The height reachability rulebook is triggered by a single rule that I shove into the action-processing rules. c.f. the Electrified example.]

This is the check-heights rule:
    if the action requires a touchable noun and the noun is not nothing begin;
        change the reaching actor to the actor;
        change the reaching object to the noun;
        consider the height reachability rules;
        if the outcome of the rulebook is the stop action processing outcome, stop the action;
    end if;
    if the action requires a touchable second noun and the second noun is not nothing begin;
        change the reaching actor to the actor;
        change the reaching object to the second noun;
        consider the height reachability rules;
        if the outcome of the rulebook is the stop action processing outcome, stop the action;
    end if.

The check-heights rule is listed before the basic accessibility rule in the action-processing rules.

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