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.
Constructors
Section titled “Constructors”| Constructor | Description |
|---|---|
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")Properties
Section titled “Properties”position
Vector3 The world-space position of this location.
Methods
Section titled “Methods”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.
Operators
Section titled “Operators”Location supports arithmetic and equality operators — loc + distance is equivalent to world.locationByMoving(loc, distance).
| Operator | Description |
|---|---|
location + distance | Returns a new Location moved distance meters in the direction of travel |
location - distance | Returns a new Location moved distance meters against the direction of travel |
locationA == locationB | Value equality (same segment, end, and distance) |
String Conversion
Section titled “String Conversion”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>© 2026 Giraffe Lab LLC. All rights reserved.