Connecting relates various rooms to various rooms. The verb to be connected to implies the connecting relation.
A dorm is a kind of room. A dorm can be open or closed.
Understand "enter [any room]" as dorm-entering. Understand "go into [any room]" as dorm-entering. Dorm-entering is an action applying to one visible thing. Carry out dorm-entering: If the noun is a dorm not connected to the location of the player, say "You see no such room here."; if the noun is a dorm connected to the location of the player and the noun is closed, say "The door is closed; it would be terribly impolite to just barge in."; if the noun is a dorm connected to the location of the player and the noun is open, move the player to the noun.
The problem comes when you try to provide the player with a way to LEAVE a room they have entered. I figured this would do the trick:
Understand the command "leave" as something new. Understand "leave" as leaving. Leaving is an action applying to nothing. Setting action variables for leaving: now the destination is the room connected to the location of the player. Check leaving: If the destination is nothing, say "Somehow I don't think you can do that." instead. Carry out leaving: Move the player to the destination.
But no matter how I structure the action definition, Inform always complains about the phrase "the room connected to the location of the player". It just doesn't seem to understand at all, which is strange considering that it was able to interpret "a dorm connected to the location of the player" correctly (if I take out my "leaving" definition, the system works fine, you just can't get out of any dorm you choose to enter). What's going wrong here? Am I even doing this the right way? Is there a "right way"?
Thanks,
--Alex
You don't have to actually connect rooms together for the geography to
work, you just have to fake the connection in a convincing way from the
player's point of view. I've only done two connections in the example
below, but you could theoretically do any number. (Although for large
numbers (like your dorm corridor) most buildings of that sort are
institutional, having a large number of functionally identical rooms. So
you might want to think about 'really' only having one room and just
faking the differences anyway.)
(Thanks to Emily Boegheim for helping me with the if-syntax.)
(code)
"halls and walls" by Totally testing
The long hallway is a room. "A long panelled gallery with the stairs
down to the main floor at its western end. The great hall is behind it
to the south, and the library and study are next door to each other on
the north side of the hallway."
Check going by name in long hallway (this is the special hallway rule):
if the noun is not a room, say "You can't think how you'd do that.";
if the noun is the study or the library, move the player to the noun;
[These bits of scenery are just to allow the "enter library" command to
work.]
Study-thing is scenery in long hallway. "You can't really see into the
study from here." Study-thing can be enterable. Study-thing is
enterable. Instead of entering the study-thing, move the player to the
study. Understand "study" as the study-thing.
Library-thing is scenery in long hallway. "You can't really see into the
library from here."
Library-thing can be enterable. Library-thing is enterable. Instead of
entering the library-thing, move the player to the library. Understand
"library" as the library-thing.
Instead of going north in long hallway, say "Both the library and the
study are north of here. Please say which place you want to go to."
Going by name is an action applying to one thing.
Understand "[any room]" as going by name.
Understand "go to [any room]" as going by name.
Understand "go [any room]" as going by name.
Check going by name:
if the noun is the location, say "You're already in [the location]."
instead;
if the noun is adjacent begin;
let aim be the best route from the location to the noun, using doors;
say "(heading [aim])[command clarification break]";
try going aim;
otherwise;
say "That room is not connected to [the location].";
stop the action;
end if;
Carry out going by name:
say "[line break]";
move the player to the noun;
The library is a room. "A spacious room with many book-cases round the
walls."
Instead of going south in the library, move the player to the long hallway.
The study is a room. "A cosy, panelled den. The long hallway is outside."
Instead of exiting in the study, move the player to the long hallway.
The stairway is a room. It is west of long hallway.
The great hall is a room. The great hall is north of long hallway.
The armory is a room. The armory is north of the great hall.
Test me with "go north/ go study/ out/ go armory"
(/code)
Of course the special movement code for the study and library doesn't
deal with doors, you'd have to add that handling if you wanted it.
hth
--jz
p.s. - should have added that this code is closely based on
"Misadventure", ex.271 in the current documentation.
--jz
"The room connected to the location of the player" is not valid syntax
because there's no way to know there is only one room connected to the
location. However, "a random room connected to the location of the
player" would work. Since you only seem to plan on having one room
connected to each dorm room, the "random" part would always choose the
hall. With this solution, you still have to connect the hall to the
dorms AND the dorms to the hall, and now "leaving" the hall would take
you to random dorm room. That's arguably reasonable, but I don't
think it's what you really want. There may be a better way.
Your implementation of leaving implies you want the dorm rooms
"connected" only to the hall, and not to each other. (You could still
use doors to make adjoining rooms, but you could not "connect" them.)
That being the case, you can change the relation definition and name
the room that the dorms are connected to.
Connecting relates various rooms to one room (called the destination).
You can then connect the dorm rooms to the hallway (you don't have to
connect the hall to anything) and then refer to the "destination of
the location" for the purposes of leaving. Setting action variables
becomes unneccessary.
Perhaps better yet, you can simplify the whole implementation and
ditch the relation if you make the hall *outside* of each dorm room.
You can then understand "leave" as exiting. The adjacency relation
will then suffice for the entering action as long as you test on the
location's adjacency to the noun and not the other way around. That
method, however, does not provide such an opportunity to learn about
implementing new relations.
-- Joe
Correct.
> Connecting relates various rooms to one room (called the destination).
>
> You can then connect the dorm rooms to the hallway (you don't have to
> connect the hall to anything) and then refer to the "destination of
> the location" for the purposes of leaving. Setting action variables
> becomes unneccessary.
That seems to make a lot more sense (I'm not at all clear on how the
bit that comes after "relates" works), but I tried this and I'm still
getting an error. Not the same error, though. Here's the abbreviated
version of what I have:
--------------------------------------------------
Connecting relates various rooms to one room (called the destination).
The verb to be connected to implies the connecting relation.
A dorm is a kind of room. A dorm can be open or closed.
Understand "enter [any room]" as dorm-entering. Understand "go into
[any room]" as dorm-entering. Dorm-entering is an action applying to
one visible thing. Carry out dorm-entering: If the noun is a dorm not
connected to the location of the player, say "You see no such room
here."; if the noun is a dorm connected to the location of the player
and the noun is closed, say "The door is closed; it would be terribly
impolite to just barge in."; if the noun is a dorm connected to the
location of the player and the noun is open, move the player to the
noun.
Understand the command "leave" as something new. Understand "leave" as
leaving. Leaving is an action applying to nothing. Check leaving: If
the destination of the location is nothing, say "Somehow I don't think
you can do that." instead. Carry out leaving: Move the player to the
destination of the location.
The South Hallway is a room. "You may enter [list of open dorms
connected to the South Hallway] from here."
Room 101 is an open dorm connected to the South Hallway.
Room 102 is an open dorm connected to the South Hallway.
--------------------------------------------------
Inform has this to say: "You wrote 'Room 102 is an open dorm connected
to the South Hallway', but in another sentence 'Room 101 is an open
dorm connected to the South Hallway': but this looks like a
contradiction, because the same property seems to be being set in each
of these sentences, but with a different outcome."
Well, yes, I am setting the same property in both of these sentences.
Who says I can't set it more than once? That would defeat the whole
point. And of course the outcome is different: I'm applying the
property to two different rooms! What on earth is Inform really trying
to tell me?
--Alex
Alex,
Don't know why, but this works:
Room 101 is an open dorm. It is connected to the South Hallway.
Room 102 is an open dorm. It is connected to the South Hallway.
Mike
Alex,
Now that I think about it, you're _not_ setting a property. You're
establishing a relation (the connecting relation), which is why you
need some form of the verb "to be" in the sentence. That's why
Room 101 is an open dorm connected to the South Hallway.
doesn't work, and
Room 101 is an open dorm. It is connected to the South Hallway.
does. (I think.)
Mike
I just saw one minor flaw in this setup: If the player attempts to
"enter" and isn't specific enough with which room they want, the game
asks "Which do you mean?" and prints a list of every room in the game
that could match the query, regardless of whether it can be entered
from the player's location. I fixed that with the following code:
--------------------------------------------------
Rule for asking which do you mean when dorm-entering: Let the tally be
the number of open dorms connected to the location; if the tally is 0,
say "There are no dorms you can enter from here."; if the tally is 1,
move the player to a random open dorm connected to the location; if
the tally is at least 2, say "You can access [list of open dorms
connected to the location] from here. Which one did you mean?".
--------------------------------------------------
As you can see I was forced to use the "random open dorm" hack here,
but it shouldn't cause problems, aside from the fact that the usual
Inform auto-correction display (in parentheses) does not happen.
Now all I need to figure out is how to add an extra line break after
entering and leaving, so the new room name appears in the right spot.
For some reason it doesn't feel like accepting more than one action in
the If statement.
--Alex
Alex,
This should solve your line break prob as well as save you some
typing:
<code>
Connecting relates various rooms to one room (called the
destination).
The verb to be connected to implies the connecting relation.
A dorm is a kind of room. A dorm can be open or closed.
Every dorm is connected to the south hall. [this will save some
typing.]
Understand "enter [any room]" as dorm-entering. Understand "go into
[any room]" as dorm-entering. Dorm-entering is an action applying to
one visible thing.
Carry out dorm-entering:
If the noun is a dorm not connected to the location of the player,
say "You see no such room here.";
if the noun is a dorm connected to the location of the player and the
noun is closed, say "The door is closed; it would be terribly impolite
to just barge in.";
if the noun is a dorm connected to the location of the player and the
noun is open begin;
say "[command clarification break]";
move the player to the noun;
end if.
Understand the command "leave" as something new. Understand "leave" as
leaving. Leaving is an action applying to nothing.
Check leaving:
If the destination of the location is nothing, say "Somehow I don't
think you can do that." instead.
Carry out leaving:
say "[command clarification break]";
Move the player to the destination of the location.
The South Hallway is a room. "You may enter [list of open dorms
connected to the South Hallway] from here."
Room 101 and Room 102 are open dorms.
Room 103 is a closed dorm.
Rule for asking which do you mean when dorm-entering:
Let the tally be the number of open dorms connected to the location;
if the tally is 0,
say "There are no dorms you can enter from here.";
if the tally is 1 begin;
say "[command clarification break]";
move the player to a random open dorm connected to the location;
end if;
if the tally is at least 2, say "You can access [list of open dorms
connected to the location] from here. Which one did you mean?".
</end code>
Mike
--Alex