I’d like to create a scenario similar to a hallway, where multiple rooms branch off. I’m not sure what the best way to do this in Inform7 is, or with interactive fiction in general. I imagine the functionality I’d like to exist would be letting the player write “go inside Room 101”, or “enter Room 101”, and then leave with “go outside” or “exit”, but maybe there’s a more comfortable functionality I can provide.
I tried doing this, which threw errors that the different rooms being inside the Hallway contradicted each other:
I imagine I don’t want to break the Hallway into many discrete parts, because walking through it may be tedious to the player, but is there a better way that people usually implement this?
The conventional methods are either using different cardinal directions (one room is north, another northeast, another east…), using doors (allowing “enter room 101”), or both.
I don’t know if there are enough cardinal directions to make it work, especially considering that north and south are the ways out of the hallway. So it gives at maximum 6 doors (while I’m looking for a solution that works for an unbounded number of side rooms), and this solution seems uncomfortable to the player (since northwest and northeast aren’t the actual directions of the doors).
If I have to assign directions, then I wouldn’t be able to make the above work, right? Because there aren’t enough directions, and having two rooms in the same direction won’t build.
You could reduce the number of rooms. Will the player really need eight identical rooms? That could make navigation confusing.
But you could also do something like this.
Include Easy Doors by Hanon Ondricek.
Door 101 is an easydoor in the Hallway. It leads to Room 101. Understand "room" as door 101.
Outside from Room 101 is the Hallway.
[repeat as needed]
Instead of going inside when the location is the Hallway: say "You'll need to be more specific. There are a lot of doors here."
EDIT: As you have seen. Hopefully the sample code helps also.
Another way of allowing “enter room 101” and “go in room 101” would be to create a new action, room-entering, with understand lines like
Understand "enter [room]" as room-entering. Understand "go in/inside/to [room] as room-entering.
…you’d also have to make sure that you put all the available rooms in scope. Then you could have the rules for room-entering redirect the action to going in the appropriate direction, though that would still limit you to the number of available compass directions.
Hmm, the only way I can think of to do this involves a few bits of [strikeout]magic[/strikeout] advanced technique:
Hallway is a room. Kitchen is a room. The wooden door is a door. It is east of Hallway and west of Kitchen.
To decide what action name is the action-to-be: (- action_to_be -).
Opposing relates a door (called X) to a room (called Y) when Y is the other side of X from the location. The verb to oppose means the opposing relation.
Understand "[something related by opposing]" as a door when the action-to-be is the entering action.
test me with "x kitchen/enter kitchen/enter hallway".
It might actually be polite to give some sort of response to “x kitchen,” which would take away the need to do the bit about the action-to-be (which is something you can’t get out of the documentation at all–it involves going into the Inform 6 level to get something out of the parser which might well get changed in subsequent versions of Inform). Though then you would encounter some issues about what to do when the player types “x kitchen” as opposed to “x kitchen door,” which would lead to a whole other set of hairy problems.
The other stuff can be found in the documentation section on Understanding by relations and on Relations that express conditions, but this stuff is tricky. (I can never figure out whether to say “related by opposing” or “related by reversed opposing” without trial and error.)
I made an extension called EASY DOORS which is in the IDE library. It is meant do do exactly this; it allows you to place any number of directionless doors in a room.
You can write
101Door is an easydoor in hallway. It leads to Room 101. The printed name is "door 101". Understand "door 101" and "door to 101" and "door to room 101" and "room 101" and "101" as 101door.
[The understand lines allow the player to say ENTER DOOR 101, ENTER ROOM 101, ENTER DOOR TO ROOM 101, ENTER 101 all as synonyms for the door.]
Also you can use a kind to simplify creating a bunch of doors that all return back to the hallway.
A hallret is a kind of easydoor. Hallret leads to hallway. The printed name is "door back to the hallway". Understand "door back to the hallway" and "hallway/return" and "hallway door" and "door to hallway" and "return to hallway" as hallret. One hallret is in room 101. One hallret is in room 102. One hallret is in room 103. [...]
This line adds the word “room” as a synonym for one particular door. Since the door is called “door 101”, Inform allows the player to refer to it with any combination of “door” and “101”. If I add “room” to that list as well, it’ll accept “room 101” or “room 101 door” etc.