Train stops and directions

A train can go both ways (west or east), but only one direction at a time. If the current direction is west, it cannot go east. What is the easiest way to set up multiple stops (locations).

1 Like

Is this a scenario where the player boards a train and is then whisked automatically to the next station? The normal connections mechanism wouldn’t work, instead you’d need to use goto to move the player to the new location when disembarking the train, and also have some way of tracking where the train is, e.g. using an integer.

I’ll come up with an example later (as I am currently, by coincidence, on a train myself).

yes, if they board the train, they would auto go to the next stop, pending on the direction of train travel.
I was trying regular locations perhaps with a blocked path but didn’t work

1 Like

Here’s a very simple example that will do what you want. ENTER TRAIN will take you to the next location east or west, depending on which way the train is travelling (determined by the travelling_east boolean):

start_at = embankment


locations {

embankment : location "Embankment station"  ;
charing_cross : location "Charing Cross station";
piccadilly :location "Piccadilly station";
oxford_circus : location "Oxford Circus station"; 
on_the_train : location "In a train carriage";
}

booleans {
   travelling_east : boolean default = "true" ;
 
   
}

objects {
   
   train : scenery "a train" at = "embankment" ;
}
   
on_command {

: match "enter train"  {
: print "You enter the train.";
 : press_any_key ;
 : print "The doors close and the train moves off.";
 : press_any_key ;
 : if (is_at "embankment") {
    : print "After a short while, the train stops. You get off and find yourself at Charing Cross Station.";
    : set_true "travelling_east" ;
    : goto "charing_cross";
 }
 : else_if (is_at "charing_cross") {
    : if (travelling_east) {
        : print "After a short while, the train stops. You get off and find yourself at Piccadilly Station.";
    : goto "piccadilly";
    }
    : else {
          : print "After a short while, the train stops. You get off and find yourself at Embankment Station.";
    : goto "embankment";
    }
 }
 : else_if (is_at "piccadilly") {
    : if (travelling_east) {
        : print "After a short while, the train stops. You get off and find yourself at Oxford Circus Station.";
    : goto "oxford_circus";
    }
    : else {
          : print "After a short while, the train stops. You get off and find yourself at Charing Cross Station.";
    : goto "charing_cross";
    }
 }
  : else_if (is_at "oxford_circus") {
        : print "After a short while, the train stops. You get off and find yourself at Picadilly Station.";
        : set_false "travelling_east" ;
    : goto "piccadilly";
 }
 : create "train";
 : press_any_key ;
 : redescribe;
 
}
}

If you want a more elaborate simulation then you could make a separate ‘inside the train’ location and move the player to that whilst travelling. Then you’d need to set up a counter (an integer) and increment / decrement each turn depending on direction of travel, to track where the train is. Then you could check the value of the integer when the player leaves the train and goto the relevant location depending on its value. That would be one way of doing it. I can provide an example if you’re interested, but the simple implementation above may be enough for your purposes.

2 Likes

thanks for putting this together, Ill let you know

booleans {
going_west : boolean “true”;
}

barriers {
west_block : block_path {
from = City_Hall_St
to = Brooklyn_Bridge_St
block_when = going_west
message = Not permitted, the train is going in the opposite direction.
}
}

this works fine without a lot of coding (still need to do for each station) , I just need the if to change the boolean, when train has reach it’s end at west and east.

1 Like

What you’re describing is a vehicle. There is a section on vehicles in the doco or the cookbook, I can’t remember which.

A vehicle (in this case, the train carriage) should be implemented as one room so that any dropped objects travel with you. You can enter that room when the train is stopped at any of the railway stations. All railway stations have connections to the same railway carriage, but you may need a barrier to prevent entry if the train is not at the station.

Once on board, the background processing takes care of the movement of the train. When it stops at a station, you change the counter (as @ChristopherMerriner suggested). You can only get off the train when it is stopped at a station and the counter determines which station. There are no connections from the railway carriage to the stations. These are determined programmatically.

You’ll have to add some messages during the background processing to let the player know what’s going on, i.e. train starting/stopping, doors opening/closing and maybe some onboard announcements or descriptions of the scenery passing by. All the backgound processing is done in the on_tick{} section.

If you want to skip the passage of time while on the train, you can do that, but the same principles apply. Don’t forget to allow time for the player to get off the train before it starts up again and goes to the next station.

1 Like

The boat example is here: Adventuron - Cookbook

It works because you can goto the location of an object as well as a regular location. You can move the separate vehicle object around the map while the player is at the ‘inside vehicle’ location and then take them to wherever the vehicle object is when they leave it. A neat little example.

That’ll work fine, if you want the player to be able to enter directions to travel by train. You’d probably still need to implement a train object to appear at each station though (in on_describe) and handle what happens if the player tries GET ON TRAIN or ENTER TRAIN. Or perhaps the train implicitly appears when the direction is entered… There are a hundred ways of doing it, which is why implementation is such a fun and time-absorbing (surely not time-wasting) hobby!