This code creates a reason the rule stopped phrase, which returns the most recent rule to have either succeeded or failed. It’s probably good enough for use in debugging, but the whole enterprise is kind of fraught.
lab is a room.
oblong is an object based rulebook
oblong lab (this is the labial rule): say "Good job."; rule succeeds.
oblong yourself (this is the hyperspheroid rule): say "Why can't you be more like your brother?"; rule fails.
when play begins:
follow the oblong rules for lab;
if rule failed, say reason the rule stopped;
follow the oblong rules for yourself;
if rule failed, say reason the rule stopped;
To decide what rule is the reason the/-- rule stopped: (- latest_rule_result-->3 -).
Include (-
Array latest_rule_result --> 4;
-) replacing "latest_rule_result".
Include (-
[ FollowRulebook rulebook parameter no_paragraph_skips
rv ss spv;
ss = self;
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; }
spv = parameter_value; parameter_value = parameter;
! we won't need parameter again, so can reuse it
parameter = debugging_rules;
if (debugging_rules) {
DebugRulebooks(rulebook, parameter);
process_rulebook_count = process_rulebook_count + debugging_rules;
}
if ((rulebook >= 0) && (rulebook < NUMBER_RULEBOOKS_CREATED)) {
rv = rulebooks_array-->rulebook;
if (rv ~= EMPTY_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);
} else {
rv = 0;
}
} else {
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-->3 = rv;
if (debugging_rules) {
process_rulebook_count = process_rulebook_count - debugging_rules;
if (process_rulebook_count < 0) process_rulebook_count = 0;
spaces(2*process_rulebook_count);
if (latest_rule_result-->0 == RS_SUCCEEDS) print "[stopped: success]^";
if (latest_rule_result-->0 == RS_FAILS) print "[stopped: fail]^";
}
} else {
if (debugging_rules)
process_rulebook_count = process_rulebook_count - debugging_rules;
latest_rule_result-->0 = RS_NEITHER;
}
debugging_rules = parameter;
self = ss; parameter_value = spv;
return rv;
];
-) replacing "FollowRulebook";
[edited: oops. I had working code that I broke before I posted. revising.]
[ok, now it should work.]