Arranging the exits from a Room

So I’m currently testing a custom system I plan to implement and to start with i’m trying to find a way to generate a string that describes the exits out of a Room.

So far, I have this code:

Repeat with N running through adjacent rooms:
		let the way be the best route from the location to N;
		if the way is a direction:
			Now RoomExitCode is "[RoomExitCode][way]";
	say "The Generated Room Code is: [RoomExitCode]!";

That works fine, and creates a string that, depending on how many exits and and what they are, lists them out in a single line.
Example: The Generated Room Code is: northeastwest.

The issue is I want to compare the resulting string to a lookup entry in a table, but the string that gets built seems to find the rooms and get assembled in the order the exits were declared, thus can’t be relied upon to match a text comparison.

So if I defined the east exit before the north exit for example, then the string would be eastnorthwest, not northeastwest.

I need a way to tell Inform to repeat through rooms and exits but give them in a compass order N/E/S/W.

In essence, I have a single entry in my lookup table for those three directions, that is “northeastwest”, which that string should now be able to match with and then the other entries in that row can be used.
But unless the string gets built in that order, it won’t match and find that row.

I really don’t want to create however many combinations of north east west in the lookup table i’d need to cater for the order it builds that string, let alone the moment there is also a south…or an Up/Down too!. :stuck_out_tongue:

Maybe Repeat through Adjacent Rooms is not the ideal way to list the exits for this purpose?

Using pathfinding (‘the best route’) is, for Inform, a relatively CPU expensive way to scan the exits.

Have a look at the code of the extension Exit Lister by Eric Eve, which is in the public library set of extensions, and see how he does it – by scanning directions.

Scanning by directions may have the side-effect of solving your second issue, because the directions will always be scanned in the same order. Off the top of my head I don’t know if it’s NESW, but if it’s not, you only have to arrange your data to match the order in which Inform declares the directions.

-Wade

Well sort of. Finding the best route to an adjacent room doesn’t take long! Particularly if (ironically) ‘Use slow route-finding’ is set, so that an entire stored map of connections never has to be rebuilt

Just a thought- do you want to include exits via doors, or even locked doors, here? See Documentation 6.14.

Otherwise the ‘best route’ to the room beyond the door to the east may set off in a different direction entirely.

If you decide to stick with the ‘best route’ approach to exit-finding.

PS there is another potential problem to listing all exits using ‘best route’- if there are two exits to the same adjacent room, it will only find one of them

Using a slightly altered version of Erik Eve’s Exit Lister code did the trick!

Repeat with way running through directions:
		Let AdjRoom be the room way from the location;
		if AdjRoom is a room:
			Now RoomExitCode is "[RoomExitCode][way]";

produces a string that is always a predictable hierarchy: NorthSouthEastWestUpDownInsideOutside.
The 'if AdjRoom is a room:" check ensures that only the valid exits out of the above string are used.

Therefore no matter which order the exits are created/defined, if there’s a north exit for example, it will always be at the start of the string, followed by south if there, followed by east etc.

You can also find a more description-inline Exit Lister there.