It still wouldn’t help the case described above: wanting to distinguish that the always successful rule isn’t in the Foo rules; it just happened to get followed in the course of following the Foo rules.
That said, I thought I’d take a whack at maintaining a global with the current rulebook. And a frustration of mine for a while has been that FollowRulebook has a silent vestige of much better rule-debugging output in it…
- mentioning the names of rulebooks, not just rules
- indenting the output to match the rulebook nesting level
- for rulebooks that take a parameter, what parameter was passed
- explicitly stating whether a rulebook suceeded or failed
Once upon a time I got parts of that working, but I have no idea where that code is now. So I just recreated a much better version of it. I threw in the reason the rule stopped from Equivalent of "reason the action failed" for an object-based rulebook? - #4 by Zed 'cause, well, why not? If I was doing this much violence to FollowRulebook it’s not like that much more could hurt.
I’d make a Borogove snippet of it, but Quixe’s Glkote balks at it sending output to a window with an active line input request. This is a fair cop, but I don’t feel like dealing with it now. git built with either of Cheapglk or Glkterm are okay with it; gargoyle complains about it but doesn’t refuse to run.
Lengthy code
lab is room.
bob is a person in the lab.
To decide what K is a/an/-- (v - a value) cast as a/an/-- (name of kind of value K): (- {v} -).
debug-rules is a number that varies.
the debug-rules variable translates into Inter as "debug_rules".
debug-val is a kind of value. The debug-vals are debug-off, debug-on, debug-on-steroids.
To set debug to (d - debug-val): (- debug_rules = ({d} - 1); -).
debug-setting is an action out of world applying to one debug-val.
understand "set [debug-val]" as debug-setting.
carry out debug-setting: set debug to the debug-val understood.
report debug-setting: say "Debugging set to [(debug-rules + 1) cast as a debug-val].".
foo is an object based rulebook producing an object.
foo lab: rule succeeds with result yourself.
foo yourself: rule succeeds with result lab.
llm is a rulebook producing a text.
first llm when the location is not the lab: do nothing. [ set debug-on-steroids to see this not apply ]
llm (this is the stochastic parrot rule):
let t be "";
repeat with i running from 1 to 50 begin;
let x be a random number from 97 to 122;
now t is "[t][x cast as a unicode character]";
end repeat;
rule succeeds with result t;
incr is a number based rulebook producing a text.
incr a number (called n): rule succeeds with result "[n + 1]".
when play begins:
set debug to debug-on-steroids;
follow the foo rules for lab;
follow the incr rules for 27;
let t be the text produced by the llm rules;
test me with "jump / bob, jump".
Include (-
[ DB_Rule R N blocked q;
if (R==0) return;
spaces(2 * process_rulebook_count);
print "[Rule ~", (RulePrintingRule) R, "~ ";
#ifdef NUMBERED_RULES; print "(", N, ") "; #endif;
if (blocked == false) "applies.]";
print "does not apply (wrong ";
if (blocked == 1) print "scene";
if (blocked == 2) print "action";
if (blocked == 3) print "actor";
if (blocked == 4) print "context";
print ").]^";
];
-) replacing "DB_Rule".
Include (- Global current_rulebook; -).
To say current rulebook: (- print (RulePrintingRule) current_rulebook; -).
Include (-
Array latest_rule_result --> 4;
-) replacing "latest_rule_result".
To decide what rule is the reason the/-- rule stopped: (- latest_rule_result-->3 -).
Include (-
[ FollowRulebook rulebook parameter no_paragraph_skips rv;
@push self;
@push parameter_value;
if ((Protect_I7_Arrays-->0 ~= 16339) || (Protect_I7_Arrays-->1 ~= 12345)) {
print "^^*** Fatal programming error: I7 arrays corrupted ***^^";
@quit;
}
if (parameter) {
self = parameter;
parameter_object = parameter;
}
parameter_value = parameter;
if ((rulebook >= 0) && (rulebook < NUMBER_RULEBOOKS_CREATED)) {
rv = rulebooks_array-->rulebook;
if (debug_rules) {
spaces(2 * process_rulebook_count);
if (rv == EMPTY_RULEBOOK) {
print "[ (";
print (RulePrintingRule) rulebook, " is empty) ]^";
}
else {
print "[... following ";
print (RulePrintingRule) rulebook;
if (parameter) {
print " on ";
if (rulebook == WHEN_SCENE_BEGINS_RB or WHEN_SCENE_ENDS_RB) PrintSceneName(parameter);
else if (metaclass(parameter)) Glulx_PrintAnything(parameter);
else print parameter;
}
print " ]^";
}
}
if (rv ~= EMPTY_RULEBOOK) {
@push process_rulebook_count;
process_rulebook_count++;
@push current_rulebook;
current_rulebook = rulebook;
if (rulebook ~= ACTION_PROCESSING_RB) MStack_CreateRBVars(rulebook);
if (say__p) RulebookParBreak(no_paragraph_skips);
rv = rv(no_paragraph_skips);
if (rulebook ~= ACTION_PROCESSING_RB) MStack_DestroyRBVars(rulebook);
@pull current_rulebook;
@pull process_rulebook_count;
if (debug_rules) {
spaces(2 * process_rulebook_count);
print "[... finished ";
print (RulePrintingRule) rulebook, " ]^";
}
}
else { ! it's an empty rulebook
rv = 0;
}
}
else { ! plain rule, not a rulebook
if (say__p) RulebookParBreak(no_paragraph_skips);
rv = rulebook();
if (rv == 2) rv = reason_the_action_failed;
else if (rv) rv = rulebook;
}
if (~~rv) latest_rule_result-->0 = RS_NEITHER;
else {
latest_rule_result-->3 = rv;
if (debug_rules) {
spaces(2*process_rulebook_count);
print "[ ";
print (RulePrintingRule) rulebook;
print " ended";
if (latest_rule_result-->0 ~= RS_NEITHER) {
print " in ";
if (latest_rule_result-->0 == RS_SUCCEEDS) {
print "success";
if (latest_rule_result-->1) {
print " producing ";
PrintKindValuePair(latest_rule_result-->1, latest_rule_result-->2);
}
}
if (latest_rule_result-->0 == RS_FAILS) print "failure";
}
print " ]^";
}
}
@pull parameter_value;
@pull self;
return rv;
];
-) replacing "FollowRulebook".
Here’s an excerpt from the test me output showing the very end of the Startup Rules, entering test me and the whole turn sequence for a jumping action (the first action taken by test me) and on into the initial steps of the subsequent turn, i.e., getting as far into the parse command rule to print the prompt for the next command.
Obviously, this is massively verbose and one is rarely going to want all of this output. I’ll have to think of options for cutting it down. But, that said, I think this gives a picture of the turn sequence and the action-processing rules that’s really useful and otherwise hard to come by.
[... finished Startup rulebook ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]
[ (after reading a command rulebook is empty) ]
[Rule "declare everything initially unmentioned rule" applies.]
[Rule "generate action rule" applies.]
[... following Setting action variables rulebook ]
[... finished Setting action variables rulebook ]
(Testing.)
[... finished Turn sequence rulebook ]
[ Turn sequence rulebook ended in success ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]
[1] jump
[ (after reading a command rulebook is empty) ]
[Rule "declare everything initially unmentioned rule" applies.]
[Rule "generate action rule" applies.]
[... following Setting action variables rulebook ]
[... finished Setting action variables rulebook ]
[... following Action-processing rulebook ]
[Rule "announce items from multiple object lists rule" applies.]
[Rule "set pronouns from items from multiple object lists rule" applies.]
[Rule "before stage rule" applies.]
[ (Before rulebook is empty) ]
[Rule "basic visibility rule" applies.]
[Rule "basic accessibility rule" applies.]
[Rule "carrying requirements rule" applies.]
[Rule "instead stage rule" applies.]
[ (Instead rulebook is empty) ]
[Rule "requested actions require persuasion rule" applies.]
[Rule "carry out requested actions rule" applies.]
[Rule "descend to specific action-processing rule" applies.]
[... following specific action-processing rulebook ]
[Rule "work out details of specific action rule" applies.]
[Rule "investigate player's awareness before action rule" applies.]
[... following player's action awareness rulebook ]
[Rule "player aware of his own actions rule" applies.]
[... finished player's action awareness rulebook ]
[ player's action awareness rulebook ended in success ]
[Rule "check stage rule" applies.]
[ (check jumping rulebook is empty) ]
[Rule "carry out stage rule" applies.]
[ (carry out jumping rulebook is empty) ]
[Rule "after stage rule" applies.]
[ (After rulebook is empty) ]
[Rule "investigate player's awareness after action rule" applies.]
[Rule "report stage rule" applies.]
[... following report jumping rulebook ]
[Rule "report jumping rule" applies.]
You jump on the spot.
[... finished report jumping rulebook ]
[Rule "last specific action-processing rule" applies.]
[... finished specific action-processing rulebook ]
[ specific action-processing rulebook ended in success ]
[... finished Action-processing rulebook ]
[ Action-processing rulebook ended in success ]
[Rule "A first turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "every turn stage rule" applies.]
[ (Every turn rulebook is empty) ]
[Rule "timed events rule" applies.]
[Rule "advance time rule" applies.]
[Rule "update chronological records rule" applies.]
[Rule "A last turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "adjust light rule" applies.]
[Rule "note object acquisitions rule" applies.]
[Rule "notify score changes rule" applies.]
[... finished Turn sequence rulebook ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
>
complete test me output
[... following foo rulebook on lab ]
[Rule "foo lab" applies.]
[... finished foo rulebook ]
[ foo rulebook ended in success producing yourself ]
[... following incr rulebook on 27 ]
[Rule "incr a number ( called n )" applies.]
[... finished incr rulebook ]
[ incr rulebook ended in success producing 28 ]
[... following llm rulebook ]
[Rule "first llm when the location is not the lab" does not apply (wrong context).]
[Rule "stochastic parrot rule" applies.]
[... finished llm rulebook ]
[ llm rulebook ended in success producing zwdcxdyiovcbbczqilwiluyxfpgwnylgoiobdiqipxtdqnqati ]
[... finished When play begins rulebook ]
[Rule "fix baseline scoring rule" applies.]
[Rule "display banner rule" applies.]
[ (before printing the banner text rulebook is empty) ]
[ (for printing the banner text rulebook is empty) ]
Welcome
An Interactive Fiction
Release 1 / Serial number 250721 / Inform 7 v10.1.2 / D
[ (after printing the banner text rulebook is empty) ]
[Rule "initial room description rule" applies.]
[... following Setting action variables rulebook ]
[Rule "determine visibility ceiling rule" applies.]
[... finished Setting action variables rulebook ]
[... following Action-processing rulebook ]
[Rule "announce items from multiple object lists rule" applies.]
[Rule "set pronouns from items from multiple object lists rule" applies.]
[Rule "before stage rule" applies.]
[ (Before rulebook is empty) ]
[Rule "basic visibility rule" applies.]
[Rule "basic accessibility rule" applies.]
[Rule "carrying requirements rule" applies.]
[Rule "instead stage rule" applies.]
[ (Instead rulebook is empty) ]
[Rule "requested actions require persuasion rule" applies.]
[Rule "carry out requested actions rule" applies.]
[Rule "descend to specific action-processing rule" applies.]
[... following specific action-processing rulebook ]
[Rule "work out details of specific action rule" applies.]
[Rule "investigate player's awareness before action rule" applies.]
[... following player's action awareness rulebook ]
[Rule "player aware of his own actions rule" applies.]
[... finished player's action awareness rulebook ]
[ player's action awareness rulebook ended in success ]
[Rule "check stage rule" applies.]
[ (check looking rulebook is empty) ]
[Rule "carry out stage rule" applies.]
[... following carry out looking rulebook ]
[Rule "declare everything unmentioned rule" applies.]
[Rule "room description heading rule" applies.]
lab
[Rule "room description body text rule" applies.]
[Rule "room description paragraphs about objects rule" applies.]
[... following before printing the locale description rulebook on lab ]
[Rule "initialise locale description rule" applies.]
[Rule "find notable locale objects rule" applies.]
[ (before choosing notable locale objects rulebook is empty) ]
[... following for choosing notable locale objects rulebook on lab ]
[Rule "standard notable locale objects rule" applies.]
[... finished for choosing notable locale objects rulebook ]
[ (after choosing notable locale objects rulebook is empty) ]
[... finished before printing the locale description rulebook ]
[... following for printing the locale description rulebook on lab ]
[Rule "interesting locale paragraphs rule" applies.]
[ (before printing a locale paragraph about rulebook is empty) ]
[... following for printing a locale paragraph about rulebook on yourself ]
[Rule "initial appearance on supporters rule" does not apply (wrong action).]
[Rule "don't mention player's supporter in room descriptions rule" applies.]
[Rule "don't mention scenery in room descriptions rule" applies.]
[Rule "don't mention undescribed items in room descriptions rule" applies.]
[Rule "set pronouns from items in room descriptions rule" applies.]
[Rule "offer items to writing a paragraph about rule" applies.]
[Rule "use initial appearance in room descriptions rule" applies.]
[Rule "describe what's on scenery supporters in room descriptions rule" applies.]
[Rule "describe what's on mentioned supporters in room descriptions rule" applies.]
[... finished for printing a locale paragraph about rulebook ]
[ (after printing a locale paragraph about rulebook is empty) ]
[ (before printing a locale paragraph about rulebook is empty) ]
[... following for printing a locale paragraph about rulebook on bob ]
[Rule "initial appearance on supporters rule" does not apply (wrong action).]
[Rule "don't mention player's supporter in room descriptions rule" applies.]
[Rule "don't mention scenery in room descriptions rule" applies.]
[Rule "don't mention undescribed items in room descriptions rule" applies.]
[Rule "set pronouns from items in room descriptions rule" applies.]
[Rule "offer items to writing a paragraph about rule" applies.]
[Rule "use initial appearance in room descriptions rule" applies.]
[Rule "describe what's on scenery supporters in room descriptions rule" applies.]
[Rule "describe what's on mentioned supporters in room descriptions rule" applies.]
[... finished for printing a locale paragraph about rulebook ]
[ (after printing a locale paragraph about rulebook is empty) ]
[Rule "you-can-also-see rule" applies.]
[ (before listing nondescript items rulebook is empty) ]
[... finished for printing the locale description rulebook ]
[ (after printing the locale description rulebook is empty) ]
[Rule "check new arrival rule" applies.]
[... finished carry out looking rulebook ]
[Rule "after stage rule" applies.]
[ (After rulebook is empty) ]
[Rule "investigate player's awareness after action rule" applies.]
[Rule "report stage rule" applies.]
[... following report looking rulebook ]
[Rule "other people looking rule" applies.]
[... finished report looking rulebook ]
[Rule "last specific action-processing rule" applies.]
[... finished specific action-processing rulebook ]
[ specific action-processing rulebook ended in success ]
[... finished Action-processing rulebook ]
[ Action-processing rulebook ended in success ]
[... finished Startup rulebook ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]
[ (after reading a command rulebook is empty) ]
[Rule "declare everything initially unmentioned rule" applies.]
[Rule "generate action rule" applies.]
[... following Setting action variables rulebook ]
[... finished Setting action variables rulebook ]
(Testing.)
[... finished Turn sequence rulebook ]
[ Turn sequence rulebook ended in success ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]
[1] jump
[ (after reading a command rulebook is empty) ]
[Rule "declare everything initially unmentioned rule" applies.]
[Rule "generate action rule" applies.]
[... following Setting action variables rulebook ]
[... finished Setting action variables rulebook ]
[... following Action-processing rulebook ]
[Rule "announce items from multiple object lists rule" applies.]
[Rule "set pronouns from items from multiple object lists rule" applies.]
[Rule "before stage rule" applies.]
[ (Before rulebook is empty) ]
[Rule "basic visibility rule" applies.]
[Rule "basic accessibility rule" applies.]
[Rule "carrying requirements rule" applies.]
[Rule "instead stage rule" applies.]
[ (Instead rulebook is empty) ]
[Rule "requested actions require persuasion rule" applies.]
[Rule "carry out requested actions rule" applies.]
[Rule "descend to specific action-processing rule" applies.]
[... following specific action-processing rulebook ]
[Rule "work out details of specific action rule" applies.]
[Rule "investigate player's awareness before action rule" applies.]
[... following player's action awareness rulebook ]
[Rule "player aware of his own actions rule" applies.]
[... finished player's action awareness rulebook ]
[ player's action awareness rulebook ended in success ]
[Rule "check stage rule" applies.]
[ (check jumping rulebook is empty) ]
[Rule "carry out stage rule" applies.]
[ (carry out jumping rulebook is empty) ]
[Rule "after stage rule" applies.]
[ (After rulebook is empty) ]
[Rule "investigate player's awareness after action rule" applies.]
[Rule "report stage rule" applies.]
[... following report jumping rulebook ]
[Rule "report jumping rule" applies.]
You jump on the spot.
[... finished report jumping rulebook ]
[Rule "last specific action-processing rule" applies.]
[... finished specific action-processing rulebook ]
[ specific action-processing rulebook ended in success ]
[... finished Action-processing rulebook ]
[ Action-processing rulebook ended in success ]
[Rule "A first turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "every turn stage rule" applies.]
[ (Every turn rulebook is empty) ]
[Rule "timed events rule" applies.]
[Rule "advance time rule" applies.]
[Rule "update chronological records rule" applies.]
[Rule "A last turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "adjust light rule" applies.]
[Rule "note object acquisitions rule" applies.]
[Rule "notify score changes rule" applies.]
[... finished Turn sequence rulebook ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]
[2] bob, jump
[ (after reading a command rulebook is empty) ]
[ (before deciding the scope rulebook is empty) ]
[ (for deciding the scope rulebook is empty) ]
[ (after deciding the scope rulebook is empty) ]
[ (before deciding the scope rulebook is empty) ]
[ (for deciding the scope rulebook is empty) ]
[ (after deciding the scope rulebook is empty) ]
[Rule "declare everything initially unmentioned rule" applies.]
[Rule "generate action rule" applies.]
[... following Setting action variables rulebook ]
[... finished Setting action variables rulebook ]
[... following Action-processing rulebook ]
[Rule "announce items from multiple object lists rule" applies.]
[Rule "set pronouns from items from multiple object lists rule" applies.]
[Rule "before stage rule" applies.]
[ (Before rulebook is empty) ]
[Rule "basic visibility rule" applies.]
[Rule "basic accessibility rule" applies.]
[Rule "carrying requirements rule" applies.]
[Rule "instead stage rule" applies.]
[ (Instead rulebook is empty) ]
[Rule "requested actions require persuasion rule" applies.]
[ (Persuasion rulebook is empty) ]
Bob has better things to do.
[... finished Action-processing rulebook ]
[ Action-processing rulebook ended in failure ]
[Rule "A first turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "every turn stage rule" applies.]
[ (Every turn rulebook is empty) ]
[Rule "timed events rule" applies.]
[Rule "advance time rule" applies.]
[Rule "update chronological records rule" applies.]
[Rule "A last turn sequence rule" applies.]
[... following Scene changing rulebook ]
[Rule "scene change machinery rule" applies.]
[... finished Scene changing rulebook ]
[ Scene changing rulebook ended ]
[Rule "adjust light rule" applies.]
[Rule "note object acquisitions rule" applies.]
[Rule "notify score changes rule" applies.]
[... finished Turn sequence rulebook ]
[... following Turn sequence rulebook ]
[Rule "parse command rule" applies.]
[ (before reading a command rulebook is empty) ]
[ (for reading a command rulebook is empty) ]
> [ (before constructing the status line rulebook is empty) ]
[ (after constructing the status line rulebook is empty) ]