Documentation > nControl > API Reference
Three Way Switch Tile
nControl™ 2021.0
This tile controls a three way train track switch.

Introduction
The tile has three mouse click zones and the function that is performed depends on the zone that is clicked: setSwitchRight(), setSwitchStraight() or setSwitchLeft(). You can override the default function by a custom procedure.
Event Scripts
Three way switch tiles support the following event scripts:
  • Activate tile event: is executed when the tile is activated by switching to simulation of operational mode.
  • Deactivate tile event: is executed when the tile is deactivated by switching to design of configuration mode.
  • Mouse click event: is executed when the user clicks on the tile.
API Functions
Tile Specific Functions
nThreeWaySwitchTile.clickTile(zone)
Simulates a mouse click on the tile; this executes the mouse click event script. The argument zone specifies the mouse click zone where the virtual click appeared:
  • zone = 1: simulates a click in the 'go straight' zone
  • zone = 2: simulates a click in the 'go left' zone
  • zone = 2: simulates a click in the 'go right' zone
nThreeWaySwitchTile.flipSwitchRandom()
Flips the switch to a random position.
nThreeWaySwitchTile.getMouseClickZone()
Returns the zone that received the last mouse click:
  • 0 = the tile has not received any mouse clicks yet
  • 1 = the 'go straight' zone
  • 2 = the 'go left' zone
  • 3 = the 'go right' zone
nThreeWaySwitchTile.getState()
Returns the current state of the switch: nConst.ST_LEFT, nConst.ST_RIGHT or nConst.ST_STRAIGHT.
nThreeWaySwitchTile.publish(topic, data)
Publishes a message through the internal MQTT broker using the specified topic and data.
nThreeWaySwitchTile.sendMessage(data)
Sends the ASCII message data to a generic controller, e.g. a Arduino board.
nThreeWaySwitchTile.setSwitchLeft()
Flips the switch to the 'left' position.
nThreeWaySwitchTile.setSwitchRight()
Flips the switch to the 'right' position.
nThreeWaySwitchTile.setSwitchStraight()
Flips the switch to the 'straight' position.
Inherited from nTile
nThreeWaySwitchTile.clearScreen()
Clear all the text in the console window.
nThreeWaySwitchTile.getTile(label)
Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value.
nThreeWaySwitchTile.print(text)
Prints text in the console window. If the console window it not yet visible, printing text will make it visible.
nThreeWaySwitchTile.showConsole(mode)
Shows (mode = True) or hides (mode = False) the console window.
nThreeWaySwitchTile.sleep(duration)
Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5).
nThreeWaySwitchTile.timestamp()
Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events.
nThreeWaySwitchTile.localVars
Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property.
nThreeWaySwitchTile.globalVars
Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles.