Skip to content
You're reading the docs for Railroader 0.6 (the MoW Update), currently available on the Experimental branch.

Location

A Location is a position on the track network — a segment, a distance along it, and an end the distance is measured from. It has value semantics: comparing or copying a Location compares/copies the position, not a reference.

Returned by World methods like getMarkerLocation(), and by Car properties like locationFront/locationRear.

ConstructorDescription
Location(segmentId, end, distance)segmentId (string), end ("A"/"B", case-insensitive, or 0/1), distance (float, meters from end). Throws if the segment isn’t found
Location(locationString)Parses a "segmentId|end|distance" string, e.g. "jmi303|a|12.5". end is a/b, case-insensitive. Throws if malformed or the segment isn’t found
var loc = Location("jmi303", "A", 12.5)
var loc2 = Location("jmi303|a|12.5")

position

Vector3

The world-space position of this location.

flipped()

→ Location

Returns a copy with end reversed and distance measured from the new end, describing the same physical point but the opposite direction of travel.

Location supports arithmetic and equality operators — loc + distance is equivalent to world.locationByMoving(loc, distance).

OperatorDescription
location + distanceReturns a new Location moved distance meters in the direction of travel
location - distanceReturns a new Location moved distance meters against the direction of travel
locationA == locationBValue equality (same segment, end, and distance)

Interpolating a Location (or calling print() on one) formats it as <segmentId, end -> distance>:

var loc = world.getMarkerLocation("yard-lead")
print("Placing train at \(loc)")
// Placing train at <jmi303, A -> 12.500>