RailScript

RailScript Namespace Reference

This page lists every object attribute currently published by the RailKernel runtime namespace. Attributes marked writable can be changed with SET. “Planned” attributes already belong to the contract but currently return <not yet implemented>.

In simple terms

Objects are the things in RailKernel, such as trains, blocks, feedbacks and accessories. Attributes tell you something about an object, such as whether a block is occupied or how fast a locomotive is running. Events are moments when something happens, for example when a train enters a block. A RailScript contains the instructions that RailKernel executes, either when you start it yourself or automatically when such an event occurs.

Addressing objects

System values use system.attribute. Other objects use domain["name"].attribute or domain["guid"].attribute. Indexed locomotive functions use locomotive["name"].function[number].attribute.

system.projectLoaded
feedback["K31"].occupied
locomotive["Class 66"].function[0].name

Object collections

An empty selector, such as block[] or feedback[], identifies every object in that namespace domain. A route also exposes the related collections route["name"].blocks[] and route["name"].accessories[]. Use collections with FOR EACH. The loop variable represents one object at a time and exposes exactly the same attributes as the individually selected object.

commandStation[] feedback[] accessory[] switch[] signal[] block[] train[] trainType[] locomotive[] route[] script[] variable[] counter[] timer[]

FOR EACH item IN block[]
DO
    LOG item.name + ": " + item.occupied
END

FOR EACH turnout IN route["Station loop"].accessories[]
DO
    LOG turnout.name + ": " + turnout.position
END

System and project system

Examples

LOG "Project: " + system.projectName
IF system.emergencyStop THEN LOG "Emergency stop is active" END

Read-only

projectLoaded · emergencyStop · applicationVersion · osName · osVersion · osArchitecture · javaVersion · language · currentTime · uptimeMillis · commandStationCount · connectedCommandStationCount · poweredCommandStationCount · allCommandStationsConnected · projectName · projectDirty · projectRevision · scale · catalogueFile · trackCount · flexTrackCount · blockCount · feedbackCount · accessoryCount · signalCount · locomotiveCount · trainCount · trainTypeCount · routeCount · userVariableCount

Current event event

These values describe the event that started the current script. Object and train values are NULL when they do not apply; manually started scripts use event.type = manual.

Examples

LOG event.type + " from " + event.objectType + " " + event.objectName
IF event.trainName != NULL THEN LOG "Train: " + event.trainName END

Read-only

type · objectType · objectGuid · objectName · trainGuid · trainName

Command station commandStation

Collection identifier and attributes available through its loop variable: commandStation[]

Examples

IF commandStation["ECoS"].connected THEN LOG "ECoS connected" END
SET commandStation["ECoS"].powerOn = true

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onConnected · onDisconnected · onGo · onStop · onEmergencyStop · onReconnectStarted · onReconnectSucceeded · onReconnectFailed · onError · onFeedbackReceived · onAccessoryChanged · onLocomotiveChanged

Read-only

guid · name · technicalName · type · host · port · connected · vendor · model · articleNumber · firmwareVersion · hardwareVersion · serialNumber · supportsDecoderCvRead · supportsDecoderCvWrite · supportsMfxDecoderRead · supportsFeedbackDeletion · locomotiveCount · accessoryCount · routeCount · feedbackCount · feedbackModuleCount · boosterCount

Writable

powerOn

Feedback feedback

Collection identifier and attributes available through its loop variable: feedback[]

Examples

WHEN feedback["K31"].occupied DO LOG "K31 occupied" END
LOG "Feedback length: " + feedback["K31"].length

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onOccupied · onFree · onTrainEntered · onTrainExited · onUnexpectedOccupied · onEmergencyStop

Read-only

guid · name · commandStation · bus · module · contact · address · occupied · reliable · unreliable · excludeFromEmergencyStop · forwardRole · backwardRole · railCount · length · blockGuid · blockName · forwardStart · forwardEnd · backwardStart · backwardEnd · labelDefined · onOccupiedScript · onOccupiedScriptGuid · onFreeScript · onFreeScriptGuid · onTrainEnteredScript · onTrainEnteredScriptGuid · onTrainExitedScript · onTrainExitedScriptGuid · onUnexpectedOccupiedScript · onUnexpectedOccupiedScriptGuid · onEmergencyStopScript · onEmergencyStopScriptGuid

Writable

s88 · labelX · labelY · labelSizePercent · labelAngleDegrees

Accessory accessory

Collection identifier and attributes available through its loop variable: accessory[]

Examples

SET accessory["A.1"].position = STRAIGHT
LOG accessory["Station signal"].address5

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onStraight · onDiverging · onLeft · onRight · onPositionChanged · onActivated · onReleased · onPulseCompleted · onPulseFailed

Read-only

guid · name · type · commandStation · address · threeWay · address2 · address3 · address4 · address5 · protocol · defaultState · unreliable · straightDivergingSwapped · comment · half · reserved · reservedBy · state · labelDefined · onStraightScript · onStraightScriptGuid · onDivergingScript · onDivergingScriptGuid · onLeftScript · onLeftScriptGuid · onRightScript · onRightScriptGuid · onPositionChangedScript · onPositionChangedScriptGuid · onActivatedScript · onActivatedScriptGuid · onReleasedScript · onReleasedScriptGuid · onPulseCompletedScript · onPulseCompletedScriptGuid · onPulseFailedScript · onPulseFailedScriptGuid

Writable

position · labelX · labelY · labelSizePercent · labelAngleDegrees

Canvas switch switch

Collection identifier and attributes available through its loop variable: switch[]

Examples

SET switch["Platform lights"].on = TRUE
WHEN switch["Tank"].on DO LOG "Tank switch active" END

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onScript · offScript · pressScript

Read-only

guid · name · label · hint · type · defaultOn · releaseTimeMs · visibleDuringRouting · indicatorOnly · persistState · sizePercent · heightMm · userVariable · accessoryGuid · accessory · accessoryOnState · accessoryOffState · outputMode · directCommandStation · directProtocol · directAddress · triggerFeedbackGuid · triggerFeedback · triggerBehaviour

Writable

on · enabled

Signal signal

Collection identifier and attributes available through its loop variable: signal[]

Examples

SET signal["Station entry"].state = GREEN
LOG "Signal block: " + signal["Station entry"].block

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onRed · onGreen · onAspectChanged · onCommandFailed

Read-only

guid · name · manufacturer · articleNumber · productName · gauge · signalType · aspects · technology · railwayCountry · railwayCompany · x · y · heightMm · block · blockGuid · blockSide · direction · comment · linkedAccessory · linkedAccessoryGuid · linkedDecoder · onRedScript · onRedScriptGuid · onGreenScript · onGreenScriptGuid · onAspectChangedScript · onAspectChangedScriptGuid · onCommandFailedScript · onCommandFailedScriptGuid

Writable

state

Block block

Collection identifier and attributes available through its loop variable: block[]

Examples

IF block["Platform 1"].occupied THEN LOG block["Platform 1"].occupiedBy END
SET block["Platform 1"].usable = FALSE

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onOccupied · onFree · onReserved · onReleased · onTrainEntered · onTrainStopped · onTrainLeaving · onTrainExited

Read-only

guid · name · type · abstract · length · minTrainLength · maxTrainLength · forwardBrake · forwardStop · backwardBrake · backwardStop · electrified · occupied · occupiedBy · reserved · reservedBy · currentTrain · direction · turnbackPolicy · bidirectional · maximumSpeed · minimumDwellTime · waiting · deadlocked · feedbackCount · accessoryCount · signalCount · decouplerCount · firstForwardFeedback · lastForwardFeedback · forwardEntryFeedback · forwardBrakeFeedback · forwardStopFeedback · forwardExitFeedback · firstBackwardFeedback · lastBackwardFeedback · backwardEntryFeedback · backwardBrakeFeedback · backwardStopFeedback · backwardExitFeedback · labelDefined · onOccupiedScript · onOccupiedScriptGuid · onFreeScript · onFreeScriptGuid · onReservedScript · onReservedScriptGuid · onReleasedScript · onReleasedScriptGuid · onTrainEnteredScript · onTrainEnteredScriptGuid · onTrainStoppedScript · onTrainStoppedScriptGuid · onTrainLeavingScript · onTrainLeavingScriptGuid · onTrainExitedScript · onTrainExitedScriptGuid

Writable

usable · turnbackPolicy · maximumSpeed · minimumDwellTime · labelX · labelY · labelSizePercent · labelAngleDegrees

Train train

Collection identifier and attributes available through its loop variable: train[]

Examples

IF train["Intercity 1200"].placed THEN LOG train["Intercity 1200"].currentBlock END
WHEN train["Intercity 1200"].distanceFromBlockEntryMm >= 500 DO LOG "500 mm into the block" END

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onPlaced · onUnplaced · onQueued · onRouteStarted · onPaused · onResumed · onBlockEntered · onBlockExited · onStopped · onRouteCompleted · onRouteAborted · onDeadlocked · onEmergencyStop

Read-only

guid · name · locomotive · locomotiveGuid · trainType · trainTypeGuid · lengthMm · wagonGroupCount · motionSamplingEnabled · placed · newFeedback · currentBlock · currentBlockGuid · currentRoute · currentRouteGuid · distanceFromBlockEntryMm · distanceToBlockExitMm · previousBlock · previousBlockGuid · destinationBlock · destinationBlockGuid · nextBlock · nextBlockGuid · reservedBlock · reservedBlockGuid · currentFeedback · currentFeedbackGuid · direction · placedElementType · placedElementGuid · placedOffsetMm · brakeDistanceMmSpeed50 · brakeDistanceMmSpeed70 · brakeDistanceMmSpeed90 · brakeDistanceMmSpeed110 · motionSpeedMmPerSec50 · motionSpeedMmPerSec70 · motionSpeedMmPerSec90 · motionSpeedMmPerSec110 · onPlacedScript · onPlacedScriptGuid · onUnplacedScript · onUnplacedScriptGuid · onQueuedScript · onQueuedScriptGuid · onRouteStartedScript · onRouteStartedScriptGuid · onPausedScript · onPausedScriptGuid · onResumedScript · onResumedScriptGuid · onBlockEnteredScript · onBlockEnteredScriptGuid · onBlockExitedScript · onBlockExitedScriptGuid · onStoppedScript · onStoppedScriptGuid · onRouteCompletedScript · onRouteCompletedScriptGuid · onRouteAbortedScript · onRouteAbortedScriptGuid · onDeadlockedScript · onDeadlockedScriptGuid · onEmergencyStopScript · onEmergencyStopScriptGuid

Planned

speed · state · destination · route · waiting · deadlocked · automatic · reservedBlockCount

Train type trainType

Collection identifier and attributes available through its loop variable: trainType[]

Examples

LOG trainType["Intercity"].maximumSpeedKmh
IF trainType["Intercity"].alignAtPlatform THEN LOG "Platform alignment enabled" END

Read-only

guid · name · category · maximumSpeedKmh · unlimitedMaximumSpeed · accelerationFactor · brakingFactor · priority · reservationCount · reservationBeforeDeparture · alignAtPlatform · trainCount · allowedBlockCount

Locomotive locomotive

Collection identifier and attributes available through its loop variable: locomotive[]

Examples

SET locomotive["NS 1200"].speed = 64
SET locomotive["NS 1200"].function[3].active = true

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onSpeedChanged · onDirectionChanged · onFunctionChanged · onStopped · onDecoderError · onConnectionLost

Read-only

guid · name · displayName · description · comment · brand · catalogueNumber · gauge · commandStation · address · protocol · speedSteps · lengthMm · maximumSpeedKmh · locomotiveType · electric · configuredDirection · decoderUid · mfxUid · decoderTemplate · imageFile · feedbackDistanceFront · feedbackDistanceRear · volume · totalDistanceKm · totalRunningTimeMillis · functionCount

Writable

speed · direction · function[n].active

Read-only

function[n].name · function[n].type · function[n].mode · function[n].visible · function[n].directional · function[n].autoOffMs

Planned

speedKmh · moving · connected · currentBlock · currentBlockGuid · reserved · reservedBy · placed · trainName · trainGuid · minimumDecoderStep · maximumDecoderStep · calibratedSpeedTable · acceleration · braking · massSimulation · brakeCorrection · automatic · active · blocked · outOfService · maintenanceInterval · maintenanceDue · pushPullMode

Route route

Collection identifier and attributes available through its loop variable: route[]

Examples

LOG route["Station loop"].fromBlock + " → " + route["Station loop"].toBlock
MOVE "Intercity 1200" USING "Station loop" QUEUE

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onStarted · onCompleted · onAborted · onPaused · onResumed · onFailed · onBlocked · onAlternativeSelected

Read-only

guid · name · fromBlock · fromBlockGuid · toBlock · toBlockGuid · blockCount · legCount · trackCount · accessoryCount · corridorLengthMm · respectBlockDirection · continuationRoute · continuationRouteGuid · blocks[] · accessories[] · onStartedScript · onStartedScriptGuid · onCompletedScript · onCompletedScriptGuid · onAbortedScript · onAbortedScriptGuid · onPausedScript · onPausedScriptGuid · onResumedScript · onResumedScriptGuid · onFailedScript · onFailedScriptGuid · onBlockedScript · onBlockedScriptGuid · onAlternativeSelectedScript · onAlternativeSelectedScriptGuid

Planned

active · queued · reserved · reservedBy · available · blocked

RailScript script

Collection identifier and attributes available through its loop variable: script[]

Examples

RUN "Station loop sounds"
WHEN !script["Station loop sounds"].isRunning DO LOG "Sound script completed" END

Read-only

guid · name · enabled · language · isRunning

User variable variable

Collection identifier and attributes available through its loop variable: variable[]

Examples

SET variable["operatingMode"].value = "night"
LOG variable["operatingMode"].value

Read-only

guid · name · type · defaultValue · description · persistent · readOnly

Writable

value (unless readOnly)

Counter counter

Collection identifier and attributes available through its loop variable: counter[]

Examples

SET counter["departures"].value = counter["departures"].value + 1
LOG counter["departures"].value

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onChanged · onZero · onMinimumReached · onMaximumReached

Read-only

guid · name · initialValue · minimum · maximum · step · enabled · comment · onChangedScript · onChangedScriptGuid · onZeroScript · onZeroScriptGuid · onMinimumReachedScript · onMinimumReachedScriptGuid · onMaximumReachedScript · onMaximumReachedScriptGuid

Writable

value

Timer timer

Collection identifier and attributes available through its loop variable: timer[]

Examples

SET timer["station dwell"].durationMillis = 30000
WHEN timer["station dwell"].expired DO LOG "Dwell completed" END

On-triggers

These events can start a linked RailScript. Configure the script in the event or script settings of the corresponding object.

onStarted · onExpired · onCancelled · onReset

Read-only

guid · name · duration · elapsed · elapsedMillis · remaining · remainingMillis · expired · enabled · comment · onStartedScript · onStartedScriptGuid · onExpiredScript · onExpiredScriptGuid · onCancelledScript · onCancelledScriptGuid · onResetScript · onResetScriptGuid

Writable

durationMillis · running