General question: Rule responses vs Instead/Say vs Check/Say

I have only just come across the first of those three, since I didn’t read the documentation all the way through from front to back; only now that I am running into some text-modifying troubles have I read this particular subsection. However, I have come across the other two many times, and it seems that all three can be used to produce a response to a particular action under certain conditions. Presumably instead/say and rule responses can be used for responses to things other than game actions, and rule responses can be referred to, but beside that – if I have even understood that much correctly – what distinguishes those three? Are there core, essential distinctions, or are any distinctions details of usage? (Is this even a valid dichotomy? I can’t think up a better way to express what it is I’m curious about.)

I’d suggest that you start your research by reading page 12.2, followed by 19.1 and 19.2. That should give you a starting point for understanding this stuff.

Looking up those subsections, it seems that they are ones I have read before. Actually, looking at the flowchart in 12.2, I remember wondering to myself even then what the practical difference between check-instead and instead were (that is to say, in cases where the check behavior is something like “if x: do y instead”), so it seems I haven’t advanced in understanding since then.

Well, except maybe to say that subsuming stuff under check-instead seems more flexible? Which might not even be a correct understanding. So far as I fumble along, I have used instead statements instead of adding stuff to a check for the following purposes: in order to redirect two (edit: or more) different actions in one go; in order to target a specific object; and in order to take up fewer lines. (On reflection, the latter two are probably related.)

Not sure what you mean by check-instead. Maybe something like

check inserting it into: if the second noun is the stuffed alligator: now the noun is nowhere; say "The alligator comes to life and gobbles up [the noun]." instead.
If memory serves (my Inform is very rusty), tacking on the “instead” here is more or less equivalent to adding a final line that says “stop the action.”

This has to do with the default outcomes of rulebooks. See page 19.11. The default for the instead rulebook is failure, but the default for the check rulebook is no outcome. When there’s no outcome, the command processing continues. That is, when the check rules have been consulted, if there’s no outcome Inform proceeds to the carry out rules for the action, and so on.

This is one of the less obvious aspects of I7. It has always seemed a little obtuse to me that the default outcomes of the before, instead, check, carry out, and after rulebooks are not mentioned on page 12.2.

I’m a bit confused, but see if this makes any sense. I’ve neglected in the “poorly written rule” to place the item taken into the player’s hands, and since “instead” overrides the rest of the rules, the action fails despite appearing to the player that it worked. In the alternate check rule, that is not necessary because “check” and “carry out” do not overrule all the other built-in rules for taking, and the player receives the object correctly.

[code]“Heist of Misadventure” by Hanon Ondricek

Use scoring.

The Vault of Treasures is a room. “At last you’ve made it past the deadly lasers, swung nimbly over the security ponds full of piranha, and avoided the deadly rabid guard poodles to make it here to your destination. There’s only one thing left to do: steal the diamond.”

The treasure case is a closed, openable, transparent container in Vault of Treasures. The description is “This is where the diamond is kept - at th e bottom of a glass box made of four-inch thick bulletproof glass, filled with salt water and a school of deadly elecric eels.”

A school of deadly electric eels is in treasure case. The description is “They swim around the diamond, menacingly protecting it.”

Some electrician’s gloves are in Vault of Treasures. They are wearable.

The Hope Diamond is in treasure case. The description is “It’s the treasure you’ve come to steal.”

Instead of taking the hope diamond (this is the poorly written rule):
if the player does not wear electrician’s gloves:
end the story saying “ZZZAP! You were killed by the electric eels!”;
otherwise:
say “You grasp your treasure in your hands. Finally, it’s yours, all yours! Suddenly you feel a bit woozy…surely the curse can’t be for real! You certainly hope the legends are not true!”;
increase the score by ten.

[switch the rules by commenting out the Instead above and uncommenting the two rules below]

[Check taking the hope diamond (this is the correctly written rule):
if the player does not wear electrician’s gloves:
end the story saying “ZZZAP! You were killed by the electric eels!”

Carry out taking the hope diamond for the first time:
say “You grasp your treasure in your hands. Finally, it’s yours, all yours! Suddenly you feel a bit woozy…surely the curse can’t be for real! You certainly hope the legends are not true!”;
increase the score by ten.]

Test steal with “open case/take diamond”.
Test steal2 with “open case/wear gloves/take diamond/i/take diamond”.[/code]

Never mind that I’ve also neglected to account for the fact that the player can pick up the eels safely and remove them from the case, but taking the diamond is still a death-end.

Also the “correctly written” rule should also check that the diamond is in the treasure case, and that the eels are in the treasure case, but I didn’t think this out past demonstrating the difference between “instead” and “check/carry out”

Note that in Hanon’s correctly written rule, the reason he didn’t need to write “stop the action” or “instead” was because the rule contains an “end the story,” which should cut off the rule and everything else.

But in any case, one of the nice things about using “check” instead of “instead” is that it allows the rest of the rule mechanisms to run, and this can let you write much more general rules. For instance, we might want to do something like this:

Bedroom is a room. A thing can be scary. A thing is usually not scary. A thing can be examined. A thing is usually not examined. The security blanket is a thing in Bedroom. The description is "Your security blanket makes you feel so much better when you hold it." The clown painting is a scary thing in Bedroom. The description is "It's a painting of a clown, its mouth wide open and laughing." Carry out examining something: now the noun is examined. Check examining a scary thing: if the player does not hold the security blanket, say "It's too scary! You can't bring yourself to look...." instead. After examining the clown painting when the clown painting was not examined: say "Why were you so scared of this?" Before examining an examined thing: say "Again you look at [the noun]." Test me with "x painting/x blanket/x blanket/take blanket/x painting/x painting/drop blanket/x painting".

If we put the entire behavior for examining a scary thing into an Instead rule instead of a check…instead, then our carry out and after rules would never run for scary things, and that would mess up the more general mechanisms we want to happen.

By the way, we need “when the clown painting was not examined” rather than “for the first time” because “for the first time” counts attempts, not successes, so that rule wouldn’t ever fire if we tried and failed to examine the painting. (I tried it that way the first time–this is actually something that Hanon would need to change in his code, if there were a way of failing to take the diamond without killing yourself.) Also Inform generally recommends printing text in After and Report rules rather than Carry Out rules unless the action itself is something that’s supposed to print text, like examining–maybe this is to make it easier to change how the text is printed with After and Report rules.

I see. So it is not entirely off the mark to treat “check x: … instead.” as more flexible than plain old “instead:”. In which case plain old “instead:” seems a bit of an oddball thing with limited application…?

Also, for some reason I had been acting under the assumption that writing a “carry out” for an existing action would override the original “carry out” – an assumption that, upon conscious reflection, makes little sense considering that “check” doesn’t override the original checks. Welp.

(Report, ah, report. I have used it occasionally as a semihemidemi analogue of the debugging “print”, but is there any reason to use it other than tidiness? Not to diminish the importance of tidiness, of course.)

What about rule responses, though? Are they indeed just for referenceability? (Referentiality? Er. The ability to be referenced.)

What do you mean when you say “rule responses”? Do you mean something like this:

Instead of taking an ethereal thing (this is the can't take ethereal things rule):
    say "[Our] hand [pass] straight through [the noun]." (A).

[...]

let R be the can't take ethereal things rule response (A).

The main reason for creating “responses” like this is if you’re writing an extension and you want to let authors customize your text a bit.

Rule responses are nice if you want to keep everything exactly the same except print different text. Like, the parser error internal rule response (E) is the message that prints “You can’t see any such thing.” In my ParserComp game this is usually going to apply when a robot can’t see something, so I put this in:

The parser error internal rule response (E) is "[The person asked] [cannot] visually identify any such thing."

–and presto! I’ve replaced “You can’t see any such thing” with something more suitably robotic like “Beta cannot visually identify any such thing” without having to worry about what the original rule that prints it is or anything. (In fact in this case I think the original rule is some deep Inform 6 thing that would be a paaaaaiiiin to replace by hand. Before the rule response system was implemented, changing these messages involved using an extension that twiddled things in I6 somehow.)

[As Draconis says, you probably don’t need to create a response unless you’re writing an extension, in which case it’s good to give the authors who will use the code a quick way to change the text that your rules print.]

As for Instead and Report rules, there’s a rather frighteningly detailed guide for when to use them in section 12.21 on Writing with Inform. The idea is that “Instead” is when you want one particular action to be treated in a special way. Like in Holme’s example of the tire swing, you might want to say something like:

Instead of jumping in the Bottom of the Grave: say "You jump up and grab the tire swing. As you do, the monster reaches for you and falls into the grave."; now the monster is in the Bottom of the Grave; move the player to the Cemetery.

Because you don’t want any of the normal mechanisms for jumping happen. You don’t want it to print “You jump on the spot” or anything like that. Instead rules block carry out and after and report and from running so they’re good for shutting down the normal mechanisms like that.

Report rules are good for printing the generic responses to an action. (Like check and carry out rules, all the applicable rules will run unless you stop them.) So if you define a new grabbing action, you could write a “Report grabbing” rule that gives the generic response to grabbing–and then Instead or After rules you write for more specific cases will cut off those Report grabbing rules from running.

Hope this is some help.

Check, Carry Out, and Report rules are part of the normal course of an action being performed.

Check rules should normally only verify that the action is possible, and print a refusal of some kind if it isn’t. Carry Out rules should usually only change the game state, and Report rules should usually only print a message reporting the action was successful.

Check chanting (this is the can't chant an unknown magic word rule):
    unless the player knows the noun:
        say "You don't know that magic word.";
        rule fails.

Carry out chanting:
    now the current magic word is the noun.

Report chanting:
    "You solemnly chant [the noun] several times.".

Before rules run before everything else (Even Check and Instead), so they’re used for rules that should be run even if the action would fail the Check stage. Often, they’re used to automate player behaviour; the standard rule that opens doors before walking through them is a Before rule.

Before waving a magic wand:
    if the current magic word is nothing:
        say "(first chanting an appropriate word)[command clarification break]";
        try silently chanting frobnitz.

After rules run after the action has taken place, but they (normally) bypass the Report rules, so their most common use is to change the response to doing a specific thing, or to tack on some logic at the very end of an action.

After taking the bag full of lampreys:
    say "Taken... oh, God, it's covered in slime.";
    now the player is grossed out.

After taking a treasure in the presence of the palace guard:
    now the palace guard is suspicious;
    continue the action. [We want to continue the action so that the normal Report phase will take place]

Instead rules bypass the check/carry out/report mechanism entirely, so they’re used for special cases or ad-hoc behaviour. Inform implements several actions that are blocked by default (You can see them in the Index of a compiled project) such as kissing, burning, cutting, tasting, and so on. If you want to give one of those actions an ad-hoc effect in just one specific situation, Instead rules are commonly used for that, because those actions are blocked by a Check rule. However if you want to give those actions a proper, thorough implementation, the normal way to do it is to unlist the standard Check rule for them and build a full set of Check, Carry Out and Report rules. They’re also used to prevent an action that would otherwise succeed, or to convert actions into one another to make the parser seem smarter.

Instead of pulling a lever:
    try switching off the noun.

Instead of drinking the invisibility potion in the presence of the palace guard:
    say "The palace guard is right there! He'd see us do it!".

Instead of kissing the baron:
    say "Alas, you no longer have the strength.";
    end the story finally saying "Your tragic love story will echo through the ages".

Rule responses are present in extensions and the standard library, and changing them is useful when you just want to change the text but the behaviour of the rule is fine. You can use the Index to see each action’s rules, and with them each of the associated responses.

print standard inventory rule response (A) is "Your possessions are few:[line break]".

A notable thing, though, is that there are a few specific rulebooks that are less often used but apply in particular cases. In the example of the box full of deadly eels, you could write:

[Reaching Into rules apply to all persons, not just the player; this code assumes there are no NPCs that might try to reach into the treasure case]

Definition: A container is electrified if it holds the school of deadly electric eels.

Rule for reaching inside an electrified container:
    if the electrician's gloves are not worn by the player:
        end the story saying "That was actually quite painful";
    otherwise:
        allow access.

Instead of taking the school of deadly electric eels, say "They wriggle out of your grasp.".

This will affect not just trying to take the Hope Diamond, but also anything that might involve touching. For more on reaching inside rules, see §12.16 in the I7 documentation.

Oh, no, INSTEAD is very useful and powerful, which is why it’s so easy to misuse. For example, if you have a “car” vehicle with an openable door, and the player types ENTER THE DOOR you want to use instead to direct it - “Instead of entering the car door, try entering the car.” The problem is people using instead to blanket-fashion override stuff. “Instead of taking something” would cause a lot of havoc unless you’re doing something like a ghost that is unable to actually pick up anything.

That threw me for the longest time too. There are rulebooks and when you write a CHECK rule, you’re adding it to the “check rulebook” where it is considered with everything else. To take something out is a different syntax. I was for the longest time fretting “how will it know when my rule applies?” but it does. Occasionally you’ll want something to take precedence; in that case you can write “First check taking the spoon…” which will stick that rule at the start of the rulebook. You can also put rules at the end (usually a catchall for a complicated set of circumstances) as “Last check taking the spoon…”

Report is especially useful when you get into NPCs taking actions on their own, because REPORT only applies if the actor is visible.

Report Stuart examining the pocketwatch: say “Stuart scrutinizes the timepiece quizzically.”

won’t be printed if I’m not in the room with him, whereas

After Stuart examining the pocketwatch: say “Stuart scrutinizes the timepiece quizzically.”
Carry out Stuart examining the pocketwatch: say “Stuart scrutinizes the timepiece quizzically.”

will be printed even if I can’t see Stuart unless I throw in more explanation like “After Stuart examining the pocketwatch when Stuart is in the location…” which gets a little nuts because REPORT is built to care for scope and visibility.

And plus, you can take advantage of the new flexible syntax for default messages so you don’t have to write lots of “Report taking the live wire when the actor is the player… Report taking the live wire when the actor is Jim…” because Inform will change “{The actor] [doesn’t] want to be electrocuted” appropriately.

Hm, I see. Thank you for your explanations! The practical problem I am having with separating Carry Out and Report is mostly that with actions whose successful results vary in a way intended to be visible to the player, duplicating all the ifs in a second rule seems a bit, hrm, contrarily untidy. Though of course if the player sees only the one “say” regardless, it is easy then to understand sticking that into a Report.

edit: Speaking of, I tried using the “first check” trick on the “You must supply a second noun” default response for a specific action – which of course is not a response I want to straight-up replace across the board using “now the response is”, since presumably it is used for all actions that apply to two things – but I guess checking for appropriate number of nouns takes place before action rulebooks and can’t be preempted by saying “first” or anything? I even tried “first before”, as absurd as that sounds. Oh well.

For the thing in your edit, try the “for supplying a missing second noun” activity (see section 18.32 of Writing with Inform). Like this:

For supplying a missing second noun while unlocking: say "What do you want to unlock [the noun] with, Jenni? Huh? What do you want to unlock [the noun] with?"

This can even be used to actually supply the missing second noun:

For supplying a missing second noun while unlocking: if the player carries something (called the opener) that unlocks the noun: say "(with [the opener])[command clarification break]"; now the second noun is the opener; otherwise: say "You don't seem to have anything to unlock that with."

Which will make Jenni much happier.

For this to happen you have to have written an Understand line with a missing second noun, like this:

Understand "unlock [something]" as unlocking it with.

Note that there’s only one noun even though the action applies to two things. But if you’re getting “You must supply a second noun,” you’ve already got one of those, I think.

Yeah, I put that Understand in because I wanted a custom response rather than letting the parser automatically guess a random second noun (which it was kind of doing, and I Did Not Like This). As you can see that didn’t work out as I had planned – but I will try the For! Hm, I have barely read any of section 18. Must remedy, or at least file under an appropriate reference number in my brain. Thanks!

Yes, chapter 18 can be approached as Lots Of Random Stuff That Might Turn Out To Be Useful. The first several sections are kind of advanced stuff but the list of built-in activities has lots of very useful stuff.