Rules vs rulebooks: having parameters?

So I wrote this bit of code which does what I want:

[code]maindir is a list of directions variable. maindir is { north, west, south, east }.

the big hut is a room. the long ravine is east of the big hut.

Rule for printing a parser error when the latest parser error is the can’t see any such thing error:
abide by the dir-error rules for location of player; [check this room and any adjacent room descriptions]
repeat with Q running through maindir:
abide by the dir-error rules for room Q of location of player;
continue the action;

the dir-error rules are a room based rulebook.

a dir-error rule for a room (called myr) (this is the room text in command check rule):
if myr is nowhere, continue the action;
let X be indexed text;
now X is “[myr]” in lower case;
replace the text “[’]” in X with “”;
replace the text “-” in X with " ";
repeat with J running from 1 to number of words in X:
let Y be word number J in X;
if the player’s command matches the text “[Y]”, case insensitively:
say “You don’t need to do anything to [myr] by name to complete the game.”;
the rule succeeds;
continue the action;

test me with “x hut/x ravine”.
[/code]

Now, I had to create a rulebook to get a rule to apply to a room. Trying, say,

a rule for a room (called myr) (this is the room text in command check rule):

Didn’t work. Is it possible to create a rule that acts on a room without defining a rulebook? Or are rulebooks expressly the only way to define specific rules with specific targets?

I’m using 6G60 but this code worked in 6M & I also realize there may be a new feature in 6L/6M, which would be motivation to start using the newer release(s).

Thanks!

It looks like standalone rules do not have conditions.

You can get the rulebook parameter by referring to the “parameter-object” global variable. So:

The dir-error rules are a room based rulebook.
A dir-error rule for a room (called myr) (this is the check-2 rule):
	say "Check-2 [myr].";

This is the check-1 rule:
	say "Check-1 [parameter-object].";

The check-1 rule is listed in the dir-error rules.

Instead of jumping:
	follow the dir-error rules for the location.

However, if you are making standalone rules which will not go into a rulebook at all, it’s easier to define a phrase instead.

Great, thanks! I figured I was probably doing a bit more than I needed to, and I appreciate learning how to clean my code up.

This’ll help with some other things I wanted to try. It’s odd–while I’ve written a lot of I7 code, I haven’t done much with “this is the x rule” style syntax (mostly used instead/check/report/after), and I’m finally seeing and appreciating their specific use.

I’ve never found much use for defining a rule with no rulebook.

You could do it and then add the rule to two different rulebooks (I think), but that seems unnecessarily confusing.

Well, looking at what I’ve been trying to do, it looks now like I might as well have been defining a rulebook & probably should have been.

For instance, I wrote a “GO TO [room]” command and “HINT” command where I say (roughly)

[code]a room has a rule called avail-rule. completed-rule of a room is usually trivially-false rule.

check gotoing: consider the avail-rule of noun; if the rule failed, say “You can’t go there right now.” instead;[/code]

[code]a room has a rule called completed-rule. completed-rule of a room is usually trivially-false rule.

check hinting: consider the completed-rule of location of player; if the rule succeeded, say “There’s nothing left to do here. Try somewhere else.” instead;

this is the trivially false rule: the rule fails;
[/code]

Which…works, but I felt I was missing the point. There could be the availability rules and the room-completed rules, and so forth, and it’d (at the very least) make for easier-to-read code.

So (I think) I see what Inform is doing a lot better now.

For that specific situation I would make a rulebook (not a rule) called room availability. Then I’d define room availability rules for specific rooms, and a catch-all rule at the end.