Ordering carry out rules

Consider this:

Lab is a room. "This is the lab."

The ball is in the lab. "The ball is rolling about on the floor."

This is the extraneous rule:
	say "There is no justification for this rule.";
	
[The extraneous rule is listed after the room description body text rule in the carry out looking rules.]

The extraneous rule is listed before the room description paragraphs about objects rule in the carry out looking rules.

This yields:

Lab
This is the lab.

There is no justification for this rule.

The ball is rolling about on the floor.

Switching which of the last two lines is commented yields:

Lab

This is the lab.

The ball is rolling about on the floor.

There is no justification for this rule.

Why is this? The two room description rules are listed consecutively in the carry out looking rules. Why is putting my new rule after the body text rule apparently not honored? (Using the rules command confirms that in the second case the room description paragraphs about objects rule is indeed called before my rule.)

I don’t know for sure, but I think it’s due to this:

The collapsing bridge rule is listed before the moving doorways rule in the instead rules.

Instead of being placed in specificity order in the whole “instead” rulebook, the “collapsing bridge” rule would now be placed in specificity order only in the first half of the “instead” rulebook - the rules from the start up to (but not including) the “moving doorways” rule. To reiterate: that doesn’t necessarily mean it will be immediately before the “moving doorways” rule; it will be placed according to Inform’s usual sorting rules within that range.

(from §19.4. Listing rules explicitly)

Combined with this:

If no Law is able to decide, X and Y go into the rulebook in order of their appearance in the source text - that is, whichever is defined first appears earlier in the rulebook and therefore takes priority.

(from §19.16. The Laws for Sorting Rulebooks)

(And the Carry out looking rules from the Standard Rules are defined first, so are listed earlier in the respective range.)

So in one case, when you specify that your rule Y should be listed before a certain rule R, Inform will try to place it according to its sorting laws somewhere in the rulebook up to (but not including) the rule R, and since it’s not more specific than the rules from the Standard Rules, those will end up first, so Y will be directly before R.

In the other case, when you specify that your rule Y should be listed after a rule R, Inform will try to place it somewhere in the rulebook after R, and Y will again end up last in comparison to the rules from the Standard Rules (looking at the RULES command, that’s what happens: the extraneous rule is called at the end of the carry out stage, right before the after stage).

1 Like

This makes a lot of sense, and I think you’re definitely correct here. Thank heavens for people who are better readers than I. Thanks!

1 Like

[PEDANTIC EXTRA COMMENTARY FOR OTHERS] If you can imagine your code being read top-to-bottom, the default is any new rule you place goes on the top of the specific rulebook stack unless you specify it goes after or before another rule, or first or last as in Last check taking inventory puts it at the end of the “check taking inventory” rulebook and First check taking inventory puts it at the top overriding any other rule order except other First check... rules which again apply in code-order.

It took me a while to get over this “how does Inform know what order my rules need to happen in?” and the answer is “usually it doesn’t matter” since it’s able to check all the rulebooks for rules that apply specifically and non-specifically and you’re just adding more rules to each one - until you get to the place where rule-firing messages make more sense in a specific order or you need to clarify order of operations to make sure one rule goes before another - like you want to make sure every rule in the book is considered and fires before printing a “Well, that was useless.” type of message.

1 Like