Describing the direction of another room in the room description, if the rooms might move: a solution not a question

Just throwing this out there because it’s a simple thing that required a bit of source diving to do cleanly.

I’ve got some rooms whose orientation changes relative to each other in the course of the game. This means a description like, “A doorway to the east leads to the bathroom” or whatever suddenly needs some string substitution logic. Here’s a fairly straightforward implementation I just coded up. If anyone knows of something even simpler that I missed (in adv3), please let me know.

Sample code, in the form of a playable(-ish) “game”:

#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>

modify playerActionMessages
        okayTiltowait = 'The world around you shifts. '
;
DefineIAction(Tiltowait)
        execAction() {
                startRoom.toggleExits();
                defaultReport(&okayTiltowait);
        }
;
VerbRule(TiltoWait)
        'tiltowait' : TiltowaitAction verbPhrase = 'tiltowait/tiltowaiting';

modify Room
        directionToRoom(rm) {
                local d;

                foreach(d in Direction.allDirections) {
                        if(self.(d.dirProp) == rm)
                                return(d.name);
                }
                return(nil);
        }
;


startRoom:      Room 'Void'
        "This is a featureless void.  The other room lies to the
        <<directionToRoom(otherRoom)>>. "
        north = otherRoom
        toggleExits() {
                if(north == otherRoom) {
                        north = nil;
                        south = otherRoom;
                        otherRoom.south = nil;
                        otherRoom.north = startRoom;
                } else {
                        north = otherRoom;
                        south = nil;
                        otherRoom.south = startRoom;
                        otherRoom.north = nil;
                }
        }
;
+me:    Person;

otherRoom: Room 'Other Room'
        "This is the other room.  The void lies to the
        <<directionToRoom(startRoom)>>. "
        south = startRoom
;

versionInfo:    GameID
        name = 'sample'
        byline = 'nobody'
        authorEmail = 'nobody <foo@bar.com>'
        desc = '[This space intentionally left blank]'
        version = '1.0'
        IFID = '12345'
;
gameMain:       GameMainDef
        initialPlayerChar = me
;

The thing described above lives in Room.directionToRoom(). It takes one arg, a reference to the room whose direction (relative to the room calling the method) you want described. A new verb, >TILTOWAIT is implemented, which toggles startRoom and otherRoom’s positions relative to each other.

The transcript:

Void
This is a featureless void.  The other room lies to the north.

>n
Other Room
This is the other room.  The void lies to the south.

>s
Void
This is a featureless void.  The other room lies to the north.

>tiltowait
The world around you shifts.

>l
Void
This is a featureless void.  The other room lies to the south.

>s
Other Room
This is the other room.  The void lies to the north.

>n
Void
This is a featureless void.  The other room lies to the south.

Dunno how useful this will be to anyone else (wandering rooms are probably a bit of a rarity in IF) but figured it was worth writing down somewhere.

4 Likes

not a rarity, a classic (Trinity) whose became later an example in inform 5 & 6.

I’m sure that deserve a place in the if-archive, as contrib to adv3. So I recommend that you upload an contrib library version of your code in said repository.

Kudos and best regards from Italy,
dott. Piergiorgio.

Yeah, I tend to make little libraries/modules out of any related bits and pieces I happen to be working on, and I usually put those on github. This example is part of a TADS3 module I’ve been working on for doing procgen map generation/layout via graph (create a generic graph object, add rooms as vertices, connections/passages as edges, and the library builds a TADS map out of it).

I’ll probably release it all publicly when I’m done with the WIP I’m doing it all for.