A framework for printing movement text ("You go west to...")

I’ve tried to search the forum about this, but it’s difficult when the search blocks words like “text” and “going.” I also thought I read about an extension that might handle this but I couldn’t find it.

I’m trying to write a framework for displaying custom text when you move to/from a room, such as “You follow a long twisting passage that eventually leads to…”. I realize that I could simply make before/after rules every time this is necessary, but I thought this might be better if I wanted to use it often.

This is horrible, but it appears to work:

[code]“New Test” by Test

A custom travel text room is a kind of room.

A custom travel text room has some text called traveling-from-north text.
A custom travel text room has some text called traveling-to-north text.
[etc. for every direction]

Place 1 is a room.
Place 2 is a custom travel text room.
Place 3 is a custom travel text room.

Place 2 is south of Place 1. Place 3 is south of Place 2.
The traveling-from-north text of Place 2 is “You travel south through a long, rusty pipe to…”.
The traveling-to-north text of Place 2 is “You scramble north along the rusty pipe again to…”.

After going south to a custom travel text room (this is the say traveling-from-north text rule):
If the traveling-from-north text of the location is not “”,
Say the traveling-from-north text of the location;
Otherwise say “Debug - there is no special south traveling text!”;
Continue the action.
[etc. for every direction]

Before going north from a custom travel text room (this is the say traveling-to-north text rule):
If the traveling-to-north text of the location is not “”,
Say the traveling-to-north text of the location;
Otherwise say “Debug - there is no special north traveling text!”;
Continue the action.
[etc. for every direction]

Test me with “s / s / n / n”.[/code]

I set up a kind of room because I figured it would be quite wasteful to assume that every room needs a set of strings that will be empty most of the time. Even so, the sheer number of strings needed for this will still end up being wasteful. Is there a more efficient way to do it?

Do you see any obvious problems this could cause, ways that it could print text erroneously? Probably the “before” parts, since we don’t know yet whether the action will succeed?

What if I want to block the text when a player uses Emily Short’s go to command?

The direction you go is the ‘noun’ of the command, and for the going action there’s a special variable called ‘room gone to’ that you can use (yes, there’s also a ‘room gone from’ variable). So you can easily write rules like:

After going: say "You travel [noun] through a long, rusty pipe to [the room gone to]."

That is good to know but to be honest, the directional noun and room gone to/from are not important in this case. I could just as easily write “The path twists and turns in on itself before opening up into…”

I’ll generally leave a trailing ellipses because the room’s name is printed right afterward.

With a system like this you would probably want unique text for coming and going from a room. With the above example, you don’t necessarily want the path to “open up” both ways.

And it seems preferable to keep the number of rooms with unique text assigned to them to a minimum. I’m not sure, let’s say there’s a room at the top of a ladder. Is it better for the upper room to handle both “you carefully climb up” and “you deftly slide down,” or should the bottom room handle climbing up and the upper room handles climbing down?

Would it be easier to use a table of rooms, directions, and text to say, and you’d check the whole table every time you move?

It seems like you’re circling around the simple solution, which is before rules (“before going down from the Attic…”). You can set up a more general framework in several ways, but it will require more code and be harder to read.

How about something like this?

[code]“Test”

When play begins (this is the set status line rule):
now the left hand status line is " [map region of the location]";
now the right hand status line is “[player’s surroundings]”.

Printing the going text of something is an activity. The printing the going text activity has a room called the previous room.

First before printing the going text of a direction (called the way) (this is the set previous room rule): now the previous room is the room (opposite of way) from the location of the player.

Last for printing the going text of a direction (called the way) (this is the print default going text rule): say “You head [way].”.

Carry out going (this is the report action rule): carry out the printing the going text activity with the noun.

Room 00 is A Room. Room 01 is east of Room 00. Room 02 is east of Room 01. Room 03 is east of Room 02. Room 04 is south of Room 00 and southwest of Room 01. Room 05 is south of Room 01, southeast of Room 00, southwest of Room 02 and east of Room 04. Room 06 is south of Room 02, southeast of Room 01, southwest of Room 03 and east of Room 05. Room 07 is south of Room 03, southeast of Room 02 and east of Room 06. Room 08 is south of Room 04 and southwest of Room 05. Room 09 is south of Room 05, southeast of Room 04, southwest of Room 06 and east of Room 08. Room 10 is south of Room 06, southeast of Room 05, southwest of Room 07 and east of Room 09. Room 11 is south of Room 07, southeast of Room 06 and east of Room 10. Room 12 is south of Room 08 and southwest of Room 09. Room 13 is south of Room 09, southeast of Room 08, southwest of Room 10 and east of Room 12. Room 14 is south of Room 10, southeast of Room 09, southwest of Room 11 and east of Room 13. Room 15 is south of Room 11, southeast of Room 10 and east of Room 14.

The City is a region. Room 05, Room 06, Room 09 and Room 10 are in The City.

The Shore is a region. Room 00, Room 01, Room 02, Room 03, Room 04, Room 07, Room 08, Room 11, Room 12, Room 13, Room 14 and Room 15 are in The Shore.

For printing the going text of a direction (called the way) when the previous room is in the shore and the location of the player is in the city (this is the print special going to city text rule): say “You head [way] to the city.”.

For printing the going text of a direction (called the way) when the previous room is in the city and the location of the player is in the shore (this is the print special going to shore text rule): say “You head [way] to the shore.”.

Test me with “se / se / se”.[/code]

Here, the report going text is dealt with by an activity with a general rule (the print default going text rule) dealing with the general case and specific rules (the print special going to city text rule and the print special going to shore text rule) dealing with specific cases.

You can easily add extra rules to deal with new cases and/or remove the general rule so that the general case prints nothing.

Hope this helps.

Actually before rules could be problematic here, because if going down from the attic was blocked by a check or instead rule, the before rule would still run.

Don’t you mean this?

Carry out going: say "You travel [noun] through a long, rusty pipe to [the room gone to].".

After going rules are especially bad as they prevent the room description from being shown.

I wouldn’t say bad, so much as treacherous–if you have

after going: [or after going successfully] say "The next bit should not be deleted."; continue the action;

That should work.

But it’s a nuisance to remember & I forget it all the time.

I suppose you’re right, it will probably be easier to set up a unique rule for each room unless I decide to do this very often. It’s a lot of work just for a bit of flavor text that many people won’t even read.

climbingstars, that’s not quite what I was going for either, but it is a neat bit of coding that I will keep in mind for future use!

Here’s some example output for what I am imagining:

[code]Cave
You are in a dark cave. The walls are damp and knobbly with outcroppings of rock. A glint of sunlight gleams from the cave opening to the south.

s

Blinking as you adjust to the sudden sunlight, you stumble out of the cave onto…

Sparkling Beach
This beach is covered with sand that shines like diamonds. A cave opens to the north, and a small path twists into the jungle to the east.

e

The damp jungle ground is cool beneath your feet compared to the hot sand. You brush undergrowth aside as you follow the path some distance to…

Jungle Hut
A dilapidated hut is here. You can probably go west or something.[/code]

I don’t necessarily want automatically generated text, I was just hoping for a more elegant solution than a rule for every exit from every room. I can just use carry out going, though.

Carry out going happens after the “after” rule, so I can be sure it will happen when the player succeeds in going? Do you have a thought as to how I could prevent this text from appearing when using Emily’s go to command?

Anything can be problematic if the rest of the game gets complicated. This is one reason that general frameworks and extensions are hard – they have to allow for many coding styles. But most of the time the simple before rule does what you want. You build the fancier (longer, more complicated) solution when you need it, not pre-emptively.

Right. I’d probably try to do it this way:

[code]A custom travel text room is a kind of room.

A custom travel text room has some text called transition text.

Carry out going from a custom travel text room: say the transition text of the room gone from.

The Place is a custom travel text room. The transition text of the place is “[if going north]Blinking as you adjust to the sudden sunlight, you stumble out of the cave onto[if going south]The damp jungle ground is cool beneath your feet compared to the hot sand. You brush undergrowth aside as you follow the path some distance to[end if] …”

Another Place is a custom travel text room. The transition text of another place is “[if going east]Du går och går, men kommer aldrig till[if going west]Du går över daggstänkta[end if] …”

[etc.]
[/code]

That is excellent, I didn’t think of that. Easy and a little more concise than making a lot of separate rules.