I just read Ron Newcomb’s “Inform 7 for Programmers.” What a great resource - thanks Ron!
The section on “paradigm leaning” gave me a lot to think about regarding rulebooks and rule-based vs. function-based code. But I’m not quite sure how to use rulebooks to make a decision:
For purposes of this example, let’s assume that “say [text]” doesn’t have the disambiguating power that it does, and we must choose an interlocutor to say the text to. How does this solution look to you?
[code]The alley is a room. The street is north of the alley. Bob is a man in the street. Carol is a woman in the street. The Bank is north of the street. The manager is a woman in the bank. The teller is a man in the bank. The Office is north of the Bank. The insurance salesman is a man in the office.
The current interlocutor is a person that varies.
choosing an interlocutor rules is a rulebook.
Definition: a person is other if it is not the player.
A choosing an interlocutor rule:
If there is exactly one other person in the location:
now the current interlocutor is a random other person in the location;
If there is no other person in the location, say “There’s no one to talk to.”;
If the number of other people in the location is greater than one, say “Please be more specific about who to say that to.”;
Rule for choosing an interlocutor when the player is in the bank:
now the current interlocutor is the teller;
Understand the command “say” as something new.
Generally talking is an action applying to one topic. Understand “say [text]” as generally talking.
Check generally talking:
Consider the choosing an interlocutor rules;
If the rule failed, stop the action.
Carry out generally talking:
try answering the current interlocutor that the topic understood.
Instead of answering:
say “’[the topic understood],’ you say to [the noun].”
test me with “say hello/n/say hello/n/say hello/n/say hello”
My questions are these:
Do I have to use a global variable to get my rules to return a usable value? Is it the best way or is there a more I7-like way?
Is it appropriate to use “If the rule failed, stop the action” or is there a more elegant way to do that?
Should I used “abide” instead of “consider?” If I do, then “rule succeeds” is the wrong outcome, and we’re back to the old problem that you can’t skip the remaining rules in a rulebook without aborting the current action.