[I7] Before removing it from

I feel like I’m about to ask a newbe question… but I can’t figure out what’s going on, so I’ll ask it anyway! I’m trying to write a before rule that captures almost all actions and redirects them to a kind of explanatory error message. (Roughly, the player only needs to use “go”, “examine” and “use”.) So I’m writing something like:

Before taking, dropping, eating, getting off, looking under or searching:
	say "No need.";
	stop the action.

However, this doesn’t seem to work for the actions that have ‘it’ in the action name. E.g., this code doesn’t compile:

Before putting it on:
	say "No need.";
	stop the action.

It gives the compiler error:

You wrote ‘Before putting it on’ , which seems to introduce a rule taking effect only if the action is ‘putting it on’. But that did not make sense as a description of an action.

But, well, that is exactly what the action is called according to the index tab. What am I missing?

This might be what you are trying to do.

Before putting something on something:
	say "No need.";
	stop the action.
1 Like

Thanks! Turns out I can even add it to that first list if I leave out the ‘something’. But I find it a bit weird, and I wonder whether it is not an oversight of manual section 7.8 that it never mentions this syntax? Of was I just being thick?

1 Like

Okay, I can now crash the compiler! :smiley:

"Test" by Victor Gijsbers

Starting room is a room.

Before taking, removing something from, dropping, putting something on, inserting something into, eating, getting off, looking under, searching, consulting something about, locking something with, unlocking something with, switching on, switching off, opening, closing, wearing, taking off, giving something to, showing something to, waking, throwing something at, attacking, kissing, answering someone that, telling someone about, asking someone about, asking someone for, touching, waving, pulling, pushing, turning, pushing something to, squeezing, saying yes, saying no, burning, waking up, thinking, smelling, listening to, tasting, cutting, jumping, tying something to, drinking, saying sorry, rubbing, setting something to, waving hands, buying, climbing, or sleeping:
	say "No need.";
	stop the action.

An internal error has occurred: the memory manager has halted Inform, which seems to be generating endless structures.

Oh fun…are there too many actions in the Before? I’ve never tried it with that many.

I’m not sure. But when I reduce the number of actions, I notice that the original compiler error reappears as soon as I put two actions which require the ‘something’ syntax in this rule. So this is fine:

Before taking, dropping, eating, getting off, looking under, searching, putting something on:
	say "No need.";
	stop the action.

But add one ‘something’ action and it throws a (surely spurious) error:

Before taking, dropping, eating, getting off, looking under, searching, putting something on, giving something to:
	say "No need.";
	stop the action.

Mixing two-noun action specifications (“putting something on”) with nounless shorthands (“dropping”) can be a problem. I don’t remember it crashing the compiler, though.

Yes, but what is strange is that I can mix one two-noun action with a bunch of one-noun actions, but not two of them. This sounds like it shouldn’t happen?

But I’m not sure whether its worth it to investigate it further at this point – from what I’m hearing, Graham has been doing so much work on Inform 7 that bug reports about the released version might be close to useless to him now. Any thoughts on that?

No idea. And since the old bug tracker is down, I can’t dig further into this.

1 Like

I don’t think the compiler likes it when you mix actions that have different arities together in any way. (Different numbers of nouns.)

I don’t recall the precise context but I do recall reading something about trouble mixing zero-noun and single-noun actions together as well.

If you have a look at WI§7.8 you’ll note that the example is examining, looking under or searching the desk – i.e. the nouns are “outside” of the alternatives, so if a noun is specified then it applies to all of the actions – and indeed at the end of the page it warns that if you specify a noun then it won’t work with actions that don’t take one.

I suspect what’s happening here is that the compiler is getting itself in knots because it wants there to be an outside noun but for single-arity actions it would be the noun and with two-arity actions it would be the second noun, and it can’t resolve that properly.

You can express precisely that (explained in WI§7.9):

Before doing something other than looking, going, examining, or using:
	say "No need." instead.

(This is also less error-prone if additional actions are added to the story later.)

In practice you’d want some additional conditions on that, otherwise it would hobble the entire story.

While putting it on is the name of the action, when you write an actual rule about it you have to replace the it placeholder with a description of some kind – something is the simplest one, but it can be more specific, such as a person, or Excalibur, or even a locked container in Treasure Vault.


Defining a “kind of action” (chapter 7.15) is a tidy way to make this work across a heterogenous collection of actions.


You can combine those things:

Looking or examining is interesting behaviour.
Going is interesting behaviour.
Putting something on the table is interesting behaviour.
Before doing something other than interesting behaviour:
	say "No need." instead.

Again, though, you need to be really careful when restricting actions like this – for example, the above also stops you taking inventory, or taking something back after putting it on the table, or taking something to be put on the table in the first place. Or even just waiting.

And you’ll probably want to restrict it to a certain location or scene, otherwise it will affect the whole story.

Thanks, the “something other” syntax and defining kinds of actions certainly will make my code more compact! (In Terminal Interface I restricted the verb set by just removing Inform’s default understanding: “Understand nothing as eating.” But there the conceit was that you were ordering around a mech with a very restricted set of built-in actions, whereas in the game I’m working on now, I want to give a more helpful message to default commands.)

Also, thanks for the cautionary remarks Gavin, but I think I know what I’m doing. :slight_smile: Restricted parser games are by now an almost venerable tradition (with games like Superluminal Vagrant Twin and The Temple of Shorgil) and I believe I have good reasons to restrict mine to the core actions of going, examining and using. (And a few assorted actions that it won’t hurt to leave in, like entering/exiting, waiting and taking inventory.) Indeed, I have seriously considered collapsing examining and using into a single command that would consist of just typing the name of the object… but ultimately decided against it.

Bear in mind that it still has to parse as a valid action in order to trigger this rule – get box will trigger the message above only if there is actually a box in the room (or, more confusingly for the player, also if already in the player’s inventory). They’ll get a different message if the box is elsewhere or nowhere at all. And if there are two boxes they’ll get a parser clarification question before it finally decides to reject the action. Having a before rule lets you bypass some checks, but not the basic parsing.

For actions that you truly don’t want to exist anywhere in your story, the best thing to do is the understand nothing as taking route.

If you’re removing an action as basic as that, though, you’ll probably also want to:

Understand nothing as taking.
Understand "get [thing]" or "take [thing]" as a mistake ("There's no need to take anything with you.").

You would have to list out the full grammar of anything you want it to recognise, however (including alternative verbs), since you’re clearing the default understanding.

Yes, I used a Before precisely because I do not want to bypass basic parsing.

That… doesn’t make much sense. None of the action rulebooks can bypass basic parsing. Before bypasses more checks than Instead, however.

(In most cases, even for this sort of thing, Instead is a better choice than Before.)

Seems like we’re massively talking past each other here, Gavin. You wrote:

Having a before rule lets you bypass some checks, but not the basic parsing.

I respond in the affirmative, telling you that:

I used a Before precisely because I do not want to bypass basic parsing.

And then you tell me that what I say doesn’t make much sense. :upside_down_face: I think we’re actually on the same page? I understand that the action rulebooks trigger only once an action has been determined by the parser and hence to do not bypass basic parsing. And I’m using the action rulebooks because I do want the parser to kick in – hence, I’m not using “Understand nothing as…”, I’m not replacing sections from the Standard Rules, and I’m not messing around with “After reading a command” stuff.

As far as I can see, we agree about everything. :slight_smile:

1 Like