Efficient Coding for Complicated Prohibited Actions

I have a door which is locked and plenty of things people could use to do things with the door. I know the engine has an in-built way to deal with this but is this acceptable or lazy?

I also ask because I’d like to be able to break things that they might use to break down the door as in “attack door with rake” or “smash door with bottle” but not break others. (assuming this is possible of course).

Beware of giving the player tools that are too general purpose. It’s very easy to overlook the way that different game objects interact.

If you give the player a prybar to open a chest (or a stuck door) with, then they’ll try said prybar on everything in the game - so you have to write all those suitable responses. They’ll be understandably miffed if your “super strength Tungsten prybar” which effortlessly opened the Security Vault later proves to be unequal to opening a stuck kitchen cabinet merely because you intended the player to “oil hinges.”

If you fancy a little light reading, I can’t do better than suggest reading Graham Nelson’s Craft of Adventure.

3 Likes

Absolutely, it’s frustrating to have a pry bar for something and not be able to use it to pry things it could handle.

In this instance, the door is described as sturdy looking and the rake is described as, “rotted at one end and rusty at the other”. However, I can conceive of people, frustrated by not finding the key, trying to use it for this purpose.

I’d like to be able to break it with the door but I’ve not located any syntax I can adapt to a “use x with y” type situation i.e. open door with rake. or attack door with rake or smash door with rake to which I can respond with a broken rake they will have to repair before they can use it for its intended purpose.

Is this functionally possible or is the inherent handling appropriate for this purpose and I should avoid this complication?

That’s because the “Attacking” action doesn’t deal with held items. You need to make a new action.

Attacking something with something
"That darned door" by "Testa"


The junk filled attic is a room. "[first time]Everything your family -- for the past three generations at least -- couldn't bear to throw away has been stacked up here. [only]Stacks of decaying cardboard boxes sag towards each other, almost meeting at the roofline.

A trapdoor leads down to the house, and a dusty door closes off the north end of the attic."

A large hammer is in the junk filled attic.

An egg whisk is in the junk filled attic.
[just to demonstrate the default message.]

The attic door is a backdrop. It is in the junk filled attic and the secret archive.

The attic door can be broken or whole. The attic door is whole. 
[Note that Inform doesn't actually know this is a door. If you look in the index, you'll see it's simply of kind "Thing". We're only going to allow the player to smash through it, so we're not interested in the whole open/closed, un/lockable business. We're simply going to use its status as a flag to allow or disallow travel. You'll notice the need to write messages to take account of players trying to do the normal things you'd expect to be able to do to a door.]

The secret archive is north of the junk filled attic. "Card-file indexes surround you on every side, except to the south."

Check going north from the junk filled attic when the attic door is whole:
	say "The attic door prevents your progress." instead;

[Below is the new action we're creating...]
Attacking it with is an action applying to two things and requiring light. Understand "attack [something] with [something preferably held]" as attacking it with.

Report attacking it with:
	say "You attack [the noun] with [the second noun] for a while. It seems to have no effect.";

Carry out attacking the attic door with the large hammer:
	now the attic door is broken;
	
Report attacking the attic door with the large hammer:
	say "At the first blow of the heavy hammer, the door panel splits. Two more heavy blows take care of the lock, and with a groan, the door sags open.";
	stop the action;

Test me with "take all / n / hit door with whisk / n / hit door with hammer / n".

That’s really good. Thank you again. It makes things clearer.

I took a run at it too. It seems to work as required but is this well formed for my situation (dodgy prose aside)?

"broken_rake" by hzdgmg and Testa

Attacking it with is an action applying to two things and requiring light. Understand "attack [something] with [something preferably held]" as attacking it with.

Fixing it with is an action applying to two things and requiring light. Understand "fix [something] with [something preferably held]" as fixing it with.

the rake is in the corral.

the rake can be broken or whole. the rake is whole.

The BARN DOOR is east of the CORRAL and west of the OLD BARN.

The BARN DOOR is a door.

The BARN DOOR is lockable and locked.

the dimpled key is a thing.

the dimpled key unlocks the BARN DOOR.

the dimpled key is in the OLD BARN.

the duct tape is in the corral.

Report attacking it with:
	say "You attack [the noun] with [the second noun] for a while. It seems to have no effect.";

Report attacking the BARN DOOR with the rake:
	say "After the first blow, the rake handle breaks in two its head dangling ineffectually.";
	now the rake is broken;
	now the printed name of the rake is "busted rake";
	stop the action.

carry out fixing the broken rake with the duct tape:
	say "all fixed.";
	now the rake is whole;
	now the printed name of the rake is "fixed rake".
	

It looks pretty good, but remember that the “Carry Out” section of a rule shouldn’t print any text (otherwise you can’t call it silently.) So the carry out section of the fixing rule should only set the “broken/whole” quality.

If you want to do the actual amending of the model world in the “after” section of an action, that’s fine, but it’s a good idea to cultivate consistency in your coding habits – otherwise when some rule contains the statement –

silently try fixing the broken bauble;

you might wonder why it doesn’t seem to do anything! (Presuming that you put the “works” in the after section as here.)

You also need a default response for the fixing action, or the player won’t get any response at all when they try fixing something you haven’t anticipated. In general, the engine tries to respond to every action that the player tries – even if’s only to give a reason the action isn’t allowed (check rules) or hasn’t done anything useful (default report rules.)

BTW, if the author has spaces in the name, you need to put it in quotes, or it won’t compile. :smile_cat:
You’re doing good, buddy!

So it should be like this?:

Report attacking it with:
	say "You attack [the noun] with [the second noun] for a while. It has no effect except to tire you out.";

Report attacking the BARN DOOR with the rake:
	say "After the first blow, the rake handle breaks in two its head dangling ineffectually.";
	now the rake is broken;
	now the printed name of the rake is "busted rake";
	stop the action.

carry out fixing the broken rake with the duct tape:
	now the rake is whole;
	
report fixing the rake with the duct tape:
	say "all fixed.";
	now the printed name of the rake is "old rake with a taped up handle".

report fixing it with:
	say "You try to fix [the noun] with [the second noun] but after some fumbling you haven't improved its functionality.".
1 Like

You got it, buddy!

Now I’m trying to incorporate synonyms for fix but having some trouble. Is there a special way to do this when you have defined an action?

Understand "repair [something]" as fixing [something].

Fixing it with is an action applying to two things and requiring light. Understand "fix [something] with [something preferably held]" as fixing it with.


You don’t need the [something] after the ‘fixing’.

Understand "repair [something]" as fixing.

It does not have to be right after you first define the action; it can be anywhere in your code.

Good luck. I remember all the headaches when I first started using Inform7.

@EpicIFer’s grammar is correct if you want the in-game command to be “Fix rake”, but if you want the command to require two objects, then you have to set up the template command with two “slots” to be filled. Imagine you’re making a new Action called “my-repair-action”. The in-game command

> Fix rake with sticky tape

becomes

Understand “Fix [something] with [something]” as my-repair-action.

(This is the most general format. We can make it more specific if we like. e.g. we can require that the objects be of a specific Kind, or we can make the action more “intelligent”, for example by asking Inform to try an implicit take. To do that we’d use the token [something preferably held].)

Usually, when we’re adding synonyms as dictionary words using Understand, Inform allows us to say:

Understand “handle” or “hoe” or “rusty/grimy” as the rusty rake.

If we’re using understand to tinker with the grammar of an action, then we have to specifically say so:

Understand the commands “repair” and “integrate” as “fix.”

Understand “Fix [something] with [something]” as my-repair-action.

At the moment, we’ve only covered the situation where the player uses some variant of words to “fix the rake with the sticky tape.” But what if the player wants to “use the sticky tape to repair the rake”? It’s the same idea, expressed in a different way.

Inform has a special grammar to allow for this:

Understand “Use [something] to repair [something]” as my-repair-action (with nouns reversed).

Now it’s always the rake that will get repaired, and not the sticky tape!

1 Like