Daily Nugget # 5: Listing door exits in room descriptions

Hi all,

In my WIP I have doors between rooms. Some of them have a purpose, some do not. But in general all room exits have a door. So I thought can I somehow make it easy to add the exits to the room? This resulted in the bit of code here (sorry no executable snippet this time):

To say room-doors:
	repeat with item running through doors in the location:
		say ". [An item] leads [direction of item from the location]";
		let otherroom be the other side of the item from the location;
		let lowerroom be "[otherroom]" in lower case;
		if the item is open or the item is transparent or otherroom is visited:
			say " to the [lowerroom]";

Then the way I use it is like this:

The description of my-room is "A description not ending in a period[room-doors].".

It will tell you all door directions, and if the other side is visible or has been visited, it will tell you what’s on the other side…

As for the lowercasing, the room names I use are generally starting with a capital letter on screen, but listing them like that in running text felt strange so I lowercase the room names there. Of course this does not cater for room names like “Hell” which might insist they stay capitalized, so if anyone has a suggestion on how to deal with room naming in a consistent way, I’m all ears…

2 Likes

As to the room-casing, I’d suggest you just ensure that proper-named or improper-named is set appropriately for each room and then lower-case the improper-named ones when you’re doing this exact thing.

[ if you're calling room-doors in an After printing the locale description of a room rule, this'll work as is;
adjust as appropriate ] 
For printing the name of an improper-named room (called the place) while printing the locale description of a room:
say "[the printed name of the place]" in lower case.

Hell is a room. [ already proper-named, will work ]
The Kitchen is a room [ already improper-named, will work ]
Hallway is an improper-named room. [ would have been proper-named, so we explicitly set improper-named ]
2 Likes