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.