Which is better: Before rule of check?

I hope this isn’t a quibble. For each action executed: Inform runs the Before, Check, Carry Out, Report, and After rules. Is there any preference when writing my exceptions in the Before rule or the Check rule. For example

Before buying an arrow: 
    If player does not have quiver, say instead ...

or putting the check inside the Check rules, e.g.

Check buying: If player does not have quiver, say instead ...
Both of these can stop the buying action if the exception is true.

1 Like

I would use Check for something like this, because if you use Check for the normal functioning of the action and Before for special cases, you can make sure the special cases always win out.

But it doesn’t make a huge difference, really.

4 Likes

I guess these things can come down to taste. I would not use Before in this case unless I needed to “get in front of” Instead and Check rules that were already in place.

My preference would probably be Check for this case. I usually use Instead rules for things that either redirect or fail.

I try to hang on to Before rules in case I need to short circuit something or else ignore visibility/accessibility.

But I think the most important thing is that you come up a schema that makes clear sense to you, so that you can easily read and troubleshoot it.

4 Likes

Check is better for standard cases, in my opinion. The appeal of Before comes from:

  1. You can make it apply to multiple actions, whereas Check is for a specific action.
  2. Before runs prior to several rulebooks that Check doesn’t. For a quasi-check like this, though, “Instead” is most relevant. It would function even for Instead exceptions!
  3. As such, and as Daniel and Drew mentioned, it is exceptional - powerful in its own special way - though that does mean it’s often in your best interest to keep it that way and only use it if you really need it.

So in this case I can’t see you needing it to be a Before rule unless, say, you had an Instead rule that lets the player “buy” a free arrow if Ganon really likes you and thus circumvents all of your usual Check rules for currency. But yes, it’s not the biggest deal in the end unless you’re running into ordering issues.

4 Likes

There’s a great discussion that I was reading just earlier today about this:

It’s more than you were asking about, but perhaps includes information you’ll be glad to learn.

In your case, putting it in a ‘check’ means that all the sensibility responses will have already run, so, i.e. there should be a shopkeeper, there should be an arrow in scope, the shopkeeper has an arrow to buy, etc. If you want to bypass all of that if the player doesn’t have a quiver, use ‘before’; if you want to hold off to make sure the buying action makes any sense first, use ‘check’.

To put it another way, imagine the player wandering the forest, seeing a rabbit, and typing >BUY ARROW. If you want to tell them, ‘You’d need a quiver before you could make use of an arrow.’ use ‘before’. If you want to tell them, ‘There’s nobody here to buy anything from.’ or ‘You’re already carrying the arrow.’ preferentially, use check.

8 Likes

Thanks for all this great advice. Several points resonated with me and I think I can code cleaner now.

1 Like

Solved, but there is wisdom in the manual: 7.3. Before rules

Their suggestion is that Before rules are good for action setup since they automatically continue the action.

[!abstract]Despite what was said in the previous section, instead rules do not quite bypass all of the usual rules. Inform knows that certain actions require light: for instance,

examining the napkin; looking; looking under the dining table

and if it is dark then none of these actions will be allowed, and any instead rules about them will not even be reached. Similarly, Inform knows that most actions require physical access to their objects: so “taking the napkin” would be blocked if the napkin were, say, inside a closed glass bottle, whereas “examining the napkin” would not. So an instead rule can only take effect if the action has already passed these basic reasonability tests.

“Before” rules genuinely precede checking of any kind. They also differ from instead rules in that they do not automatically stop the action in its tracks. Rather, they are provided as an opportunity to ensure that something else is done first. For example:

Before taking the napkin, say "(first unfolding its delicate origami swan)".

whence

GET NAPKIN
(first unfolding its delicate origami swan)
Taken.

So you could have both
Before taking the uranium: say "Okay, you've been told that's a bad idea, but..."; increase $radpoison by 1.

Check taking the uranium while the lead gloves are not worn: say "Ow that's hot and tingly. You can't hold it. That's probably about a year off your life due to cellular poisoning..."; increase $radpoison by 5 instead.

So Instead can be thought of as “stop” or “redirect”, where Before is more like “yes, and…”

Another situation - when trying not to alert guards, if the player performs a noisy action, the Before can tick the $guardalert tracker whether the noisy action is successful or unsuccessful due to an Instead or Check or other action-processing.

I would generally recommend Before for redirecting, since it runs before all the checks. If you’re redirecting action X to action Y, it’s generally the checks for action Y that matter, not the checks for action X.

4 Likes

Yup, I also recommend Before if you’re dispatching to a different action.

Determining whether an action can continue and producing an error message and stopping the action if it can’t, is what the Instead and Check rulebooks are for.

Before rules are followed prior to the basic visibility rule, the basic accessibility rule, and the carrying requirements rule. So if the action requires a touchable or carried thing as noun or second noun and you use a Before rule for this purpose, it’s running before those.

Is the error message your new rule produces still the most appropriate one for the situation if the player can’t even reach the thing in question or it’s being carried by someone else? If the answer really is yes, then a Before rule makes sense.

3 Likes

Thanks. I appreciate those tips. My style is to use Before for setting up, and Check for the error conditions.

4 posts were split to a new topic: More Before and Carry Out rule questions