Moving Sidewalk tips?

I’m messing about in Inform, and I’ve hit a bit that’s stumping me just a little.

The setting is a space station. I’d like to include a mass transit system that’s essentially a very large moving sidewalk; you step on it, and it carries you past various stations in a set order, one each turn. You can step on or off at any point. I’ve been fiddling around with the “Empire” and “Dubai” examples in the recipe book (for trains and elevators, respectively) but I can’t quite wrap my head around how to get this working.

Any help appreciated!

Station Alpha, Station Beta, Station Gamma, and Station Delta are rooms.
The Train is a room. The Train has a room called the current stop. The current stop of the Train is Station Alpha.

Every turn (this is the move the train rule):
    if the current stop of the Train is: [Move the train forward one stop.]
        -- Station Alpha:
            now the current stop of the Train is Station Beta;
        -- Station Beta:
            now the current stop of the Train is Station Gamma;
    [etc.]
    change the outside exit of the Train to the current station of the Train; [Outside from the Train leads to the Station]
    change the inside exit of the current station of the Train to the Train; [Inside from the Station leads to the Train]
    if the location is the Train or the location is the current station of the Train: [Make an announcement if the player can hear it.]
        say "A robotic voice chimes out: 'Now arriving at [the current station of the Train].'".

There are a few different ways to organize the stops (tables, lists), but hardcoding into the rules like this is probably the most direct and requires the least complication to loop around to the beginning. This might need to be changed if you have a huge number of stops.

Draconis posted first, but here’s one where I implement the sidewalk as an enterable supporter instead of a room and use a table. Also, maybe the examples in this thread would be helpful.

(The tabs in this code look weird, but they should copy and paste correctly–each column of the table is separated by a tab stop.)

[code]North Poddington is a room. Poddington Central is a room. West Umbunch is a room. South Poddington is a room. Crampton Return is a room. Crampton Return North is a room.

Umbunch Central is east of West Umbunch and north of Crampton Return. “If you want to return to the moving sidewalk, you can go east to West Umbunch or south to Crampton Return.”

Table of Moving Sidewalk Places
start message destination
North Poddington “The sidewalk carries you south to Poddington Central.” Poddington Central
Poddington Central “The sidewalk moves on to West Umbunch.” West Umbunch
West Umbunch “With a groan the sidewalk moves on to South Poddington.” South Poddington
South Poddington “The sidewalk veers east to Crampton Return.” Crampton Return
Crampton Return “The sidewalk carries you north to Crampton Return, er, North.” Crampton Return North
Crampton Return North “The sidewalk swings back round to North Poddington and turns south again.” North Poddington

The moving sidewalk is an enterable supporter in North Poddington.

Definition: a room is sidewalky if it is a start listed in the Table of Moving Sidewalk Places.

Every turn when the player is on the moving sidewalk and the location is sidewalky (this is the move the sidewalk rule): [“location”=room where the player is]
choose a row with a start of the location in the Table of Moving Sidewalk Places; [this is guaranteed to work because the location is sidewalky]
say the message entry;
move the moving sidewalk to the destination entry; [and the player will move with it, as will anything on the sidewalk]
try looking.

Carry out going to a sidewalky room (called new place) when the moving sidewalk is not in new place (this is the update sidewalk location on going rule):
now the moving sidewalk is in new place.

Every turn when the location is sidewalky and the moving sidewalk is not in the location (this is the update sidewalk location in an emergency rule):
now the moving sidewalk is in the location.

Instead of waving hands:
say “A cheery crowd that you hadn’t seen before hoists you onto its shoulders and deposits you in Poddington South.”;
move the player to Poddington South.[/code]

There’s a couple of issues. One is that the last “every turn” rule is a bit wonky–as you can see if you try “wave” and then “get on sidewalk,” the sidewalk gets moved to Poddington South before the end of the turn (it’s there) but after the room description for the new location is printed. One way to avoid this would be to write a phrase like “move the player and maybe the sidewalk to (new place - a room)” which checks whether it needs to move the sidewalk first, and then use that instead of “move the player to Poddington South.” (I can write this up more coherently if you want to see.)

Another issue is the behavior of stuff you drop on the sidewalk. Right now there isn’t anything to drop on the sidewalk, but if you did have something to drop in this code, it would just sit on the sidewalk until you got back on or left, and if you went to another sidewalky room it would magically reappear there. You’d probably want to take care of that somehow (simplest solution: Don’t let the player drop anything on the sidewalk).

Hope this is helpful!

This solution is probably the most complicated so far but it was fun fiddling with it, anyway. (And it would no doubt need tweaking.)

[code]A sidewalk room is a kind of room.

Room 1 is a sidewalk room.

Room 2 is a sidewalk room. Room 2 is east of Room 1.

Room 3 is a sidewalk room. Room 3 is south of Room 2.

Room 4 is a sidewalk room. Room 4 is west of Room 3 and south of Room 1.

A sidewalk room has a sidewalk room called the next stop.
The next stop of Room 1 is Room 2.
The next stop of Room 2 is Room 3.
The next stop of Room 3 is Room 4.
The next stop of Room 4 is Room 1.

A stretch-of-moving-sidewalk is a kind of supporter. A stretch-of-moving-sidewalk is enterable and fixed in place. The printed name of a stretch-of-moving-sidewalk is “stretch of moving sidewalk”. Understand “stretch” and “moving” and “stretch/-- of/-- moving/-- sidewalk” as a stretch-of-moving-sidewalk.

There is a stretch-of-moving-sidewalk in every sidewalk room.

Every turn when a stretch-of-moving-sidewalk encloses something:
if the player is on a stretch-of-moving-sidewalk:
say “The moving sidewalk moves you along.”;
repeat with item running through things on stretch-of-moving-sidewalks:
let old-room be the location of item;
let new-room be the next stop of old-room;
if new-room encloses a stretch-of-moving-sidewalk (called new-stretch):
now item is on new-stretch.

The player carries an apple.

Test me with “put apple on sidewalk / l / l / l / l / enter sidewalk / z / z / z”.[/code]

Re matt w’s: that’s cleaner than the method I had using tables. If you do have a large number of rooms I’d recommend that method. (Either a table or a property of each room, as bg used.)

Re bg’s: you might make a subclass of room instead of adding properties to the base type, and be careful about “enclosed by” vs “on” in your loop condition: as it is, the sidewalk will pull things out of containers and supporters. But other than that all looks good.

Oh, good point about enclosed vs. on. I will fix it. I’m not sure of the best way to fix the other part though.

I wasn’t thinking anything elaborate, just:

A sidewalk room is a kind of room. A sidewalk room has a sidewalk room called the next stop. There is a stretch-of-moving-sidewalk in every sidewalk room.
This just separates the sidewalk code from the rest of your rooms a bit more.

Ok, thanks!

Having a stretch in every room is a nice solution–it lets you keep track of things that aren’t in the player’s location and move it along naturally. My solution was kind of a hacky way of trying to simulate a backdrop (I doubt you can make backdrops enterable supporters, though I guess you can make an enterable supporter part of a backdrop) but it seems more sensible just to have the stretches be ubiquitous and not try to worry about moving the single stretch around.

We can make it a little easier to keep track of the relative arrangement of everything on the stretch-of-moving-sidewalk by moving the stretches rather than the things on them–and wrapping the movement of the stretches in a special phrase gives us a hook for printing a message about the things on the sidewalk being carried away:

[code]A sidewalk room is a kind of room.

Room 1 is a sidewalk room.

Room 2 is a sidewalk room. Room 2 is east of Room 1.

Room 3 is a sidewalk room. Room 3 is south of Room 2.

Room 4 is a sidewalk room. Room 4 is west of Room 3 and south of Room 1.

A sidewalk room has a sidewalk room called the next stop.
The next stop of Room 1 is Room 2.
The next stop of Room 2 is Room 3.
The next stop of Room 3 is Room 4.
The next stop of Room 4 is Room 1.

A stretch-of-moving-sidewalk is a kind of supporter. A stretch-of-moving-sidewalk is enterable and fixed in place. The printed name of a stretch-of-moving-sidewalk is “stretch of moving sidewalk”. Understand “stretch” and “moving” and “stretch/-- of/-- moving/-- sidewalk” as a stretch-of-moving-sidewalk. The plural of stretch-of-moving-sidewalk is stretches-of-moving-sidewalk.

There is a stretch-of-moving-sidewalk in every sidewalk room.

Every turn when a stretch-of-moving-sidewalk encloses something:
repeat with stretch running through stretches-of-moving-sidewalk:
cycle the stretch;
if the player is enclosed by a stretch-of-moving-sidewalk: [put this code here rather than in the code for cycling the stretch, to make sure that we don’t do the looking action until after the stretches are all in the right place]
say “The moving sidewalk moves you along.”;
try looking.

To cycle (stretch - a stretch-of-moving-sidewalk):
if the stretch is in the location [of the player] and the stretch does not enclose the player and something is on the stretch: [before moving]
say “The moving sidewalk carries away [a list of things on the stretch].”;
now the stretch is in the next stop of the location of the stretch; [note that this isn’t wrapped in the above if-statement]
if the stretch is in the location [of the player] and the stretch does not enclose the player and something is on the stretch: [after moving]
say “The moving sidewalk brings into view [a list of things on the stretch].”

The player carries an apple.

Test me with “put apple on sidewalk / l / l / l / l / enter sidewalk / z / z / z”.[/code]

This is a bit vulnerable to source-code order; if the sidewalk rooms (and thus their accompanying stretches) aren’t defined in the order they move in, then I think you could have a situation where it prints the message about bringing stuff into view before the message about taking stuff away, which seems undesirable. If that’s a problem you’d probably need to dump the “cycle” phrase and use the Every Turn rule to test whether anything is about to get moved into/out of the player’s location, and print an appropriate message then.

Wow, I go to bed and in the morning solutions have magically appeared. You guys are going to spoil me. :slight_smile:

At the moment I am using matt w’s solution, because tables were a thing I was trying to get a grip on anyway and elegant handling of dropped items isn’t necessary for this particular setting, and it’s working, but…

Yes, please?

Also, the setting actually runs two moving sidewalks (one north/south, one east/west, basically). I can just copy everything over, of course, but I’m wondering: is there a more elegant way to do that with kinds, or even assemblies? My attempts to do so have so far ended in error messages and sadness.

Thank you guys so much – I haven’t messed with Inform in, oh, ten years probably, and it’s nice to have help as I try to get my head back into it. :slight_smile:

The difficulty with multiple sidewalks is that “the sidewalk” becomes ambiguous. I had an idea for an elegant way to do it, let me see if I can make this work.

No problem. It’d look something like this:

[code]Instead of waving hands:
say “A cheery crowd that you hadn’t seen before hoists you onto its shoulders and deposits you in South Poddington.”;
move the player and maybe the sidewalk to South Poddington.

To move the player and maybe the sidewalk to (place - a room):
if the place is sidewalky:
now the moving sidewalk is in the place;
move the player to the place.[/code]

All the special phrase does is check whether the sidewalk is going to need to end up in the place you’re moving to, and then moves the sidewalk first. And you have to remember to use it whenever you’re using “move the player” to a room that might be sidewalky.

By the way, I noticed this:

Instead of going up, try entering the polewards Branca Two.

Inform won’t know that this applies specifically to the room you just defined. Try this instead:

Instead of going up in Station Nube, try entering the polewards Branca Two.

Here’s my code, which should hopefully be extensible to any number of sidewalks. Just add more tables. Note also that it doesn’t deal with arbitrary objects being on sidewalks as you said that wasn’t relevant to your scenario.

[rant=CODE][code]
“Sidewalks”

Volume I - Code

A moving sidewalk is a kind of enterable supporter. A moving sidewalk has a table name called the route.

Traversal relates various moving sidewalks to various rooms. The verb to visit implies the traversal relation.

When play begins (this is the create moving sidewalk routes rule):
repeat with the path running through moving sidewalks:
repeat through the route of the path:
let the place be the start entry;
now the path visits the place;
follow the update sidewalk position rule.

Every turn (this is the update sidewalk position rule):
repeat with the path running through moving sidewalks which visit the location:
move the path to the location.

Every turn when the player is on a moving sidewalk (this is the move the player on the sidewalk rule):
let the path be the holder of the player; [Inform won’t let me use a “called” name with the “is on” verb. Don’t know why.]
choose a row with a start of the location in the route of the path;
let the place be the end entry;
if there is a message entry:
say the message entry;
else:
say “The sidewalk carries you onward…”;
move the path to the place;
if the path does not visit the place:
say “You step off the sidewalk as it ends.”;
move the player to the place, without printing a room description;
remove the path from play;
follow the update sidewalk position rule;
try looking.

Volume II - Sample Scenario

Table of Primary Sidewalk Destinations
start end message
Alpha Beta –
Beta Gamma –
Gamma Delta –
Delta Epsilon –
Epsilon Epsilon “The sidewalk loops past the roundabout at Epsilon and begins again.”

Table of Secondary Sidewalk Destinations
start end
Gamma Zeta
Zeta Eta
Eta Theta

Alpha, Beta, Gamma, Delta, Epsilon, Zeta, Eta, and Theta are rooms.
Alpha is east of Beta. Beta is east of Gamma. Gamma is northeast of Delta. Delta is north of Epsilon. Zeta is north of Gamma. Eta is north of Zeta. Theta is northwest of Eta.

The primary sidewalk is a moving sidewalk. “The primary sidewalk moves slowly to the west.” The route of the primary sidewalk is the Table of Primary Sidewalk Destinations.
The secondary sidewalk is a moving sidewalk. “The secondary sidewalk speeds to the north.” The route of the secondary sidewalk is the Table of Secondary Sidewalk Destinations.
[/code][/rant]