Compound "instead of" rule

Hello,

I’m a newcomer to Inform 7.

I have a room called Hanging from Rope in which I want to change the default text for every possible direction except up and down.

I was thinking of writing an instead of rule, like this:

Instead of going east when player is in Hanging from Rope:
    say "Suspended 20 feet above the ground, your only options now are up or down."

But I’d rather not write a rule for each direction (n, e, s, w, ne, sw, etc). Is there a way to write a compound rule?

Or, is there a cleaner way of doing this?

I found a solution for the example above. All I had to do was say:

Instead of going nowhere when player is in Hanging from Rope:

And that gave me the behavior I was looking for!

2 Likes

That works. “Going nowhere” is the case if the player types a direction which has no exit.

You could also write:

Instead of going when player is in Hanging from Rope:

This would catch every direction, whether there was an exit that way or not.

1 Like

Thanks Zarf!

Inside of that “Instead of” rule, is there a way to then test whether they said they wanted to go up or down?

Something to the effect of (where the parts inside { } are the parts I don’t know how to write)…

Instead of going when player is in Hanging from Rope:
     {if player is trying to go anywhere but up or down}:
          say "Suspended 20 feet above the ground, your only options now are up or down.";
     {else} continue the action.
Hanging from Rope is a room.

Check going when player is in Hanging from Rope:
	if the noun is not up and the noun is not down:
		say "Suspended 20 feet above the ground, your only options now are up or down." instead;

Up from hanging from rope is Cliff. Down from hanging from rope is The Ground.

[Note we don’t need continue the action because check rules only intervene with action processing if they apply. Only if the rule applies and fires does it say the text and invoke instead, which stops the GOING action.]

Hanging from Rope

e

Suspended 20 feet above the ground, your only options now are up or down.

d

The Ground

1 Like

As a slight further tweak, you can shorten this to:

Instead of going nowhere in Hanging from Rope:

(from and to also work to specify locations, but only for going actions.)

Having said that, you can’t always use abbreviated in [location] clauses – for example they don’t work in Every turn, Understand .. when, or if. I’m not entirely sure why not, other than it seems to be related to whether the rule is specifically an action rule or another kind of rule.

3 Likes

Thank you all! This is extremely helpful!

There’s an extra subtlety here-- when you’re dealing with anything other than “going nowhere,” “from [room]” and “to [room]” only work when there is a valid map connection. So though “Instead of going nowhere from Hanging from a Rope” works, “Instead of going north from Hanging from a Rope” will never fire if there’s no “north” exit.

This is discussed a bit more in the documentation §7.13.

1 Like

Yes. The other fun case is that if a map connection does exist then “Before going [direction] in [room]” is equivalent to “Before going [direction] from [room]” but “After going [direction] in [room]” is equivalent to “After going [direction] to [room]”. Which makes a certain amount of sense when you think about it, but can be initially surprising.

1 Like