Repeat Through a Rulebook

version 4 by Ron Newcomb

  • Home page
  • Beginning
  • Next



  • Documentation


    This extension allows us a few basic rulebook operations: to write a repeat phrase that runs through each of the rules in a rulebook, to ask for the number of rules in a rulebook, to ask for a random rule from a rulebook, and to ask if a particular rule is currently listed in a particular rulebook. All of these operations honor the procedural rules, but we can also do them on an "unmodified" rulebook. As with the caution about changing the contents of a list while repeating through it, unusual behaviour may result if procedural phrases shuffle rules while repeating through that rulebook.

        Carry out asking Einstein about "light":
            say "He replies, 'There are [the number of rules in the carry out looking rulebook] basic laws of optics: ";
            repeat with the law of optics running through the carry out looking rules begin;
                say "the [law of optics]";
                if the law of optics is listed in the check taking rules, say " (also in the check taking rules because it was [the reason the rule ran])";
                say ", ";
            end repeat.

        Carry out asking Einstein about "Newton":
            say "He replies, 'In Newton's world there were [the number of rules in the unmodified carry out looking rules] laws of optics: ";
            repeat with the law of optics running through the unmodified carry out looking rules begin;
                say "the [law of optics], ";
            end repeat;
            say ". . . but my favorite was the [random rule from the unmodified carry out looking rules].".


    We can also ask for "the reason the rule ran", which is useful in debugging why a rule appears in a loop when we don't expect it. It is of the kind "rule-reason", and the reasons are "directly invoked", "moved before", "moved after", "ignored", and "substituted". Each reflects a procedural phrase except "directly invoked", which is the default case. (This also includes the case when a rule is called because its enclosing rulebook was called). Each reason is worded to follow "it was".

    Occasionally we may have edge cases where no valid rule exists. Uninitialized rules-that-vary default to the "little-used do nothing rule". It isn't actually a rule any more than "nothing" is an object, and we cannot set a rule-that-varies to it. But we can test for it, or simply ask if a rule is (or isn't) valid (or invalid):
        if R is the little-used do nothing rule,
        if R is a valid rule,
        if R is invalid,
        if R isn't valid,


    For great fun, we can ask for a random rule:

        The current plan is a rule that varies. [can't initialize to a random rule]
        The current repetoire is a rulebook that varies. The current repetoire is usually the repetoire of Machiavelli.
        When play begins: now the current plan is a random rule in the current repetoire.

    For cases where rules and/or rulebooks aren't named, we can refer to them by number. A rule may not have a name if an author or extension writer forgets to name it; a rulebook is only unnamed during a game compiled with the use option memory economy. Rules are numbered consecutively from 1 in the order they would currently execute, and Procedural rules can change the numbering. Rulebooks are numbered from zero up to "the number of rulebooks". Typically, the Standard Rules define the first 362 rulebooks. (Remember that Actions and Activities are implemented using three rulebooks apiece.)

        now R is rule 2 in the carry out looking rulebook;
        now R is rule 2 in the unmodified carry out looking rules;

        repeat with ID num running from 0 to the number of rulebooks begin;
            say "[ID num as rulebook] has [number of rules in ID num as rulebook] rules.";
        end repeat;


    We have new testing commands available to us. Enter a rulebook's name to list the rules currently in it, numbered accordingly. Afterward, RULEBOOK alone reprints that. Enter RULEBOOKS (the plural) for the newer rulebooks, or ALL RULEBOOKS for the whole list of 360+ in the work. Finally, when using memory economy, we may only enter RULEBOOK and the ID number for abbreviated information.
        > THE CARRY OUT LOOKING RULES
        The carry out looking rulebook:
        1: room description heading rule.
        2: room description body text rule.
        3: room description paragraphs about objects rule.
        4: check new arrival rule.

        > RULEBOOK
        The carry out looking rulebook:
        1: room description heading rule.
        2: room description body text rule.
        3: room description paragraphs about objects rule.
        4: check new arrival rule.

        > RULEBOOKS
        363: check debugging-rulebooks rulebook
        364: carry out debugging-rulebooks rulebook
        (etc.)

        > ALL RULEBOOKS
        0: Procedural rulebook
        1: Startup rulebook
        2: Turn sequence rulebook
        (etc.)

        > RULEBOOK 0
        The Procedural rulebook currently has no rules.


    Finally, a quick clarification on procedural rules and the phrases they use. Though the Inform 7 manual implies otherwise, in fact any rulebook can use the procedural phrases (listed in 18.14 "Phrases concerning rules"). The effects will only exist downstream from the phrase, as opposed to being in effect the moment a player's action is begun. This means a rulebook can ignore, substitute, etc., its own rules as well as any other rulebook's which it Considers (but not Follows). (This is also true for the procedural rulebook itself -- a procedural rule can ignore a later procedural rule!)

    [Version History

    Version 1: initial release

    Version 2: repeat loops can now take a rulebook-that-varies; testing commands added; the word "currently" can optionally be used with "is listed in"; random rules; cleaned up numbered rules

    Version 3: repeat loops now work for a single rule -- not rulebook -- given to them! Fixed bug that 5T18 had in ProcessRulebook(). Simplified the Nothing Rule section. Random now requires the word "rule/member" to follow it to prevent a clash.

    Version 4: the is/are before "currently" in the "listed in" phrases is no longer optional, to prevent a clash with Topic's "...is a <column-name> listed in the Table of..."; no longer used R as a temp variable to prevent namespace clashes

    ]