Modifying the EXIT command

Hi everyone.

I have come up with some code that seems to do what I want, but I want to see if anybody can foresee any issues that I cannot.

I modified the ‘exit’ command so that if there is exactly one room connected to the location, typing “exit” or “out” will try going the direction toward that room.

I wish for “exit” to work as it normally does in all other circumstances.

Also, rooms in my game are either “findable” or “not findable.” Almost every room is “findable.” The status line at the top of the game displays directions to “findable” rooms. This is so I can hide the directions to “unfindable” rooms in the status bar if I want to.

My thinking with my code below was that I only wanted to interrupt the normal flow of running the exit command if both of the following are true:

  1. There is exactly one findable room a direction away from the location.
  2. That findable room is not “outside” from the location.

The below might not be the most elegant way to do it, but it seems to work. I just want to see if anyone can see any major issues with it.

Wayout is a kind of value.
1wyo specifies a wayout.
The player has a wayout.
The wayout of the player is 0wyo.

Exitout is a kind of value.
1exo specifies an exitout.
The player has an exitout.
The exitout of the player is 0exo.


Before exiting:
	now the wayout of the player is 0wyo;
	now the exitout of the player is 0exo;
	let place be location;
	repeat with way running through directions:
		let place be the room way from the location;
		if place is a findable room:
			increase the wayout of the player by 1wyo;
			if place is outside from the location:
				increase the exitout of the player by 1exo;
	if the wayout of the player is 1wyo:
		if the exitout of the player is 0exo:
			repeat with way running through directions:
				let place be the room way from the location;
				if place is a findable room:
					try going the way;
					stop the action;

The only other thing I wish to change is the “exit” fail response from “But you aren’t in anything at the moment” to “You must be more specific” as the latter now makes more contextual sense. I’ve done that kind of thing before, but I can’t remember how to do it and I’m not sure how to word what I’m trying to do so I can find the answer in the Inform documentation.

Thanks in advance!

This will probably work, but I dislike the use of repeat blocks when Inform will do this for us in a much more concise manner:

A room can be findable.

The lab is a findable room. The garden is a findable room. It is west of the lab.

Before exiting:
	let rms be the list of findable rooms adjacent to the location;
	let exits be the list of findable rooms outside from the location;
	if rms is not empty and exits is empty:
		if the number of entries in rms is 1:
			let dir be the best route from the location to entry 1 of rms;
			if dir is not nothing:
				try going dir instead;

I haven’t checked to see if that will do everything you want, but it’s more idiomatic Inform 7, and a good pattern to get used to.

4 Likes

Nice! Thank you for that. That is certainly more concise than what I came up with.

this is a riff on the solitude example from the docs

might be some gotchas there but worth a look? (I was working on this while responses were posted; sorry for the redundancy!)

right way is a direction that varies.

before exiting:
	let count be 0;
	repeat with way running through directions:
		let place be the room way from the location;
		if place is a room:
			increment count;
			now right way is way;
	if count is one:
		try going the right way instead.
2 Likes

Thank you!

1 Like