A quick question about "Before"

There’s a car parked in one of my locations. It’s not significant, but it completes the scene nicely. The thing is, I need to add some responses to the player’s attempts at opening it, breaking it, etc. so that it seems real; messages like “That’s not something you can open” obviously contradict the fact that being a car, it has doors.

I have all the synonyms typed in (windows, doors, etc.), and I’ve given the car the following attributes: scenery, static, concealed (as its appearance is already noted in the room description) and, because I see no reason why the player shouldn’t be able to put things on top of it or stand on it, a supporter. It’s not a container, because there’s no way to get it open.

This works:

[code]Before [; attack:
“If you damage the car, a hunt will ensue.
Is that what you want?”;

(Taking advantage of the library reply “That was a rhetorical question.”)

	push, pull:
	"You might find this surprising, but it’s in ~park.~";


…and so forth. It works great – if the player only uses one noun. But here’s what doesn’t work: Triggering the responses when the player tries to smash the car (this is the same as “attack,” right?), or push/pull it, WITH another object.

For instance, there’s a crowbar elsewhere in the game. If the player tries to “smash the car with the crowbar,” the response is, “I only understood you as far as wanting to smash the car.” It simply doesn’t like “with.” And here’s the really weird one: If the player tries to “push the car with the crowbar” (one has to be prepared for somewhat experimental commands), he gets, “You can’t see that here” – even when the player’s holding the crowbar, and the car’s in the location.

It works okay if the player tries to “unlock” the car with something, and even “open” it with something. But not “attack” or “push/pull.”

I tried this to fix the problem thusly (you might laugh):

Before [; attack: if (second ~= 0) "Don’t hit the car with that! Someone needs a ride home later! Honestly. Some people."; "If you damage the car, a hunt will ensue. Is that what you want?"; push, pull: if (second ~= 0) "With that little thing? Apparently, you’ve lost your mind. How disillusioning."; "You might find this surprising, but it’s in ~park.~"; ],

That still doesn’t make the magic Inform fairies understand “with.” I thought that “if (second ~= 0)” would translate to: “if the player’s command has an indirect object.” Is there any way to specify a Before that means “verb WITH noun?”

I tried the DM4, but if the solution’s in there, I can’t find it.

Thanks very much. Again, I appreciate your time.

You’ll have to define additional grammar.

For example:

extend 'attack' * noun 'with' noun -> AttackWith;

And define an AttackWithSub.

Okay, I understand. Thanks very much. (Would the AttackWithSub just be the following?)


AttackWithSub will get called if none of the before routines return true. Exactly what it should do depends on your game.

For example, you might have something like:

if (second ~= sword or club)
  "That's a lousy weapon.";
if (AfterRoutines() == 0)
  "You strike ineffectively.";

You’d only really need to define an AttackWithSub or PushWithSub if you wanted to have a different standard response. The alternative is to use precisely the solution you came up with (where it checks to see if second is zero or not) - but that will only work if you have first extended the grammar:

Extend 'attack'
* noun 'with'/'using' held -> Attack;
Extend 'pull'
* noun 'with'/'using' held -> Pull;

Again, if you look at the library’s verb definitions, you’ll notice that ‘attack’ is only defined with a single noun (called a token, I think). So if the player types anything after that first noun, it will say “I only understood you as far as…”. If you look at the definition of ‘push’, you’ll notice several lines. The parser goes through them from top to bottom to see which form of the command matches the player’s input. One of the accepted forms for push is ‘noun noun’. The second ‘noun’ is the object that goes into the global variable called ‘second’. So if you type “push car with stick”, then it will correctly parse ‘car’ as the first noun (and put it in the variable called noun) and will then imagine that ‘with stick’ is supposed to be the second noun - but ‘with stick’ does not match any object in scope; hence “you can’t see any such thing”.

When you specify something with the ‘Extend’ directive, it adds your line as though it is at the end of the list.

The ‘held’ token that I’ve put in the code above is a shorthand for accepting only an object that the player is holding. You don’t have to use it; it just means that “hit car with tree” will not print your custom message, because the player isn’t holding the tree (I presume).

That’s my understanding of it all, anyway.

Thanks so much. You guys have helped me more than you know.