Here’s a little module intended to make it easier to refer to rooms and exits in actions: roomVocab github repo.
The basic “problem” this is intended to solve is that, by default, a Room
doesn’t get any vocabulary and so if you define a room like:
startRoom: Room 'Void' "This is a featureless void. ";
…you get…
>x void
The word "void" is not necessary in this story.
>x room
The word "room" is not necessary in this story.
The stock adv3 Template
for Room
includes the optional properties destName
and name
, but not vocabWords
. You can just declare vocabWords
on a Room
, but not using the stock Template
.
Anyway, the module does a couple things:
- Provides an alternate template that includes
vocabWords
- Defines a
PreinitObject
looks forRoom
s withoutvocabWords
and initializes their vocabulary withroomName
+ the literal “room”.Room
s with declared vocabularies aren’t affected. - Modifies
Room
to use a room’sdestName
as itsdisambigName
by default - Modifies
Room
to add all rooms adjacent to thegActor
’s current location to the scope list - Modifies
Room
to provide amustBeVisibleMsg
that checks to see if the room is adjacent to thegActor
and returns a different failure message if it is. This is so trying to interact with an adjacent room produces a distinct failure message (&roomUnseenAdjacent
, by default “If you want to do anything with [room name], you should go there first.”) instead of the default (&mustBeVisibleMsg
, by default “You cannot see that”).
This applies to all verbs using theobjVisible
precondition, and any precondition that usesTouchObjCondition
(which includes most sense actions). Non-adjacent rooms are unaffected.
The module also provides some utility methods on Room
that might be more generally useful, like:
isAdjacent(actor, rm)
Returns booleantrue
if there’s an exit leading from the actor’s current location to the given room.exitList(actor?, cb?)
Returns a list of all the exits apparent to the given actor (defaulting togActor
if the first arg isnil
). The second argument is an optional test function (taking two arguments: the direction and destination of a candidate exit and returningtrue
if the exit should be added toexitList()
's return value)
Each entry in the return value is an instance ofDestInfo
destinationList(actor?, cb?)
Similar toexitList()
, but returns a list of destinations (probablyRoom
s) instead ofDestInfo
instances
This is another fairly small module (just a couple hundred lines), but it’s one of those things where I found myself writing “make it easier to refer to rooms/exits” code in a couple contexts (NPC dialog, fast travel, non-compass travel, tracking NPC/player memories/knowledge) so I decided to break it out into its own module.
I think most of this is adv3-specific, because I think adv3lite already makes it easier to refer to rooms than adv3 does.