Blocking multiple exits with same response

Here’s the test code I am looking at:

Lab is a room.

North of the Lab is North Room.
South of the Lab is South Room.
East of the Lab is East Room.
West of the Lab is West Room.

Instead of going in Lab when the noun is north or the noun is south or the noun is east:
	say "That direction is blocked.".

The code works correctly, but the whole the noun is <direction> part of the conditional seems a little clunky. Is there a more elegant way to block multiple exits with the same response?

1 Like

If you want to entirely block the direction, you can change them into one-way links:

South of North Room is the Lab.  North of the Lab is nowhere.
North of South Room is the Lab.  South of the Lab is nowhere.
West of East Room is the Lab.  East of the Lab is nowhere.
East of West Room is the Lab.  West of the Lab is nowhere.

If these are the only exits from the Lab and you want them to only sometimes be blocked, you can just block going in general:

Instead of going from the Lab when lockdown is in effect:
	say "The lab doors are sealed."

(Note that this only triggers on valid exit directions.)

You can still add extra conditions to permit specific directions – for example if the north exit were immune to lockdown, you could do this:

Instead of going from the Lab when lockdown is in effect:
	if the noun is north, continue the action;
	say "The lab doors are sealed."

There’s other ways to write that sort of thing as well; another is:

Definition: a direction is lab-lockable if it is not north.

Instead of going a lab-lockable direction from the Lab when lockdown is in effect:
	say "The lab doors are sealed."

I often do this sort of thing:

Check going north in the Lab:
	instead say "Blocked."
Check going east in the Lab:
	instead try going north.
Check going west in the Lab:
	instead try going north.

It’s not shorter than your original code, but it’s easier to adjust. Each direction is its own rule so I can swap them in and out as desired. And the text response still appears exactly once, so that’s easy to edit too.

3 Likes

It sounds like you’re trying to replace the generic “You can’t go that way” with something else, any time the player tries to go a direction with no exit. Yes?
Well, a single short line is certainly simple and easier to read.

"Custom Can't Go" by artao

The Test Chamber is a room. West of the Test Chamber is the Observation Lounge.

Instead of going nowhere, say "You are held back by physics."

Will say “You are held back by physics” whenever you try a direction not available.

… But then, of course, you can add conditionals … This example is a LOT longer, but fully “playable.”
You can go back and forth between rooms and get a custom “can’t go” message when that exit doesn’t exist. In either room. But if you jump – again, in either room – the Test Chamber gets locked down and the Observation Lounge does not. Thus, if you are in the Test Chamber while it is locked down, you can’t go ANY direction, including valid exits, and are given a different “can’t go” message. … But only in the Test Chamber. You can freely move from the Observation Lounge, but get the “physics stops you” message unless you go east, in which case you gleefully enter the test chamber, locked down or not, no problem. But now you are frozen in place. And every time you jump, in either room and locked down or not, it toggles the lock down state of the test chamber. And any room could be defined as a Cell kind or not.
Anyhow, I hope it’s sensible and useful. :smiley:

"Custom Can't Go" by artao

A Cell is a kind of room. A cell can be locked down or not locked down. A cell is usually not locked down.

The Test Chamber is a Cell. The printed name is "Stark White Test Chamber - [Cell State]".

The Observation Lounge is a Cell. The printed name is "Gleaming Observation Loung - [Cell State]".
The Observation Lounge is west of the Test Chamber.

To say Cell State:
	If the location is locked down:
		Say "LOCKED";
	Otherwise:
		Say "Unlocked".

Instead of going nowhere, say "You are held back by physics."

Instead of going when the location is the Test Chamber and the Test Chamber is locked down:
	say "The Freeze It(tm) field holds you securely in place."
	
Instead of jumping:
	If the Test Chamber is not locked down:
		Now the Test Chamber is locked down;
		Say "The Observers didn't like that. Now the test chamber is locked down.";
	Otherwise:
		Now the Test Chamber is not locked down;
		Say "Jumping seems to have tripped up the system. The test chamber is no longer locked down."

1 Like