Register | Sign in

Home > Touch Control System (TCS) > TCS: Lua API


TCS: Lua API

Touch Control System supports version 5.2 of the Lua scripting language. With additional built-in functions for communication, math, user interaction, and system access, TCS gives you an incredible amount of control.




Introduction

This page is a sample of the Touch Control System Lua API. Lua scripts run when objects are loaded and/or updated, during user interaction, and after custom criteria is met. Touch Control System exposes several internal objects which provide access to additional functionality. Different Lua objects are available as the program loads and after different events are fired.

The objects available in start-up scripts, for example, offer a specific set of commands used to create environments and to set up initial object properties before any drawing occurs.



Click here for the Lua 5.2 Manual


TCS Lua API Objects




tcs

The tcs object provides access to communication, math, system access, and extended TCS functionality.



availability

Always available.



methods

FadeToScreen(string screenName)

-- Fade to a specific screen.
tcs:FadeToScreen("setup_main")

SerialCreate(string id, string portName, int baudRate, int parity, int dataBits, int stopBits, int writeTimeout, int readTimeout)

-- Create a serial connection.
-- Parity: 0 = Even, 1 = Mark, 2 = None, 3 = Odd, 4 = Space
-- StopBits: 0 = None, 1 = One, 2 = OnePointFive, 3 = Two
tcs:SerialCreate("connection_1", "COM1", 115200, 2, 8, 1, 2000, 2000)

SerialOpen(string name)

-- Open a serial connection.
tcs:SerialOpen("connection_1")

SerialRead(string name)

-- Read a single byte from a serial connection.
inByte = tcs:SerialRead("connection_1")

SerialWrite(string name, byte data)

-- Write a single byte to a serial connection.
tcs:SerialWrite("connection_1", 255)

SerialClose(string id)

-- Close a serial connection.
tcs:SerialClose("connection_1")

TcpOpen(string name, string ip address, int port)

-- Create/Open a TCP connection.
tcs:TcpOpen("connection_1", "127.0.0.1", 3000)

TcpRead(string name)

-- Read a line from a TCP connection.
inLine = tcs:TcpRead("connection_1")

TcpWrite(string name, string data)

-- Write a string to a TCP connection.
tcs:TcpWrite("connection_1", "Hello")

TcpClose(string id)

-- Close a TCP connection.
tcs:TcpClose("connection_1")

WriteLine(string text)

-- Write a string to the TCS Console.
 tcs:WriteLine("test")


properties

CursorVisible

-- Toggles the cursor and returns a bool value indicating the cursor visibility.
isCursorVisible = tcs.CursorVisible
tcs.CursorVisible = true

ElapsedTime (ReadOnly)

-- Returns an integer value indicating the total time in
--  seconds since the last update call.
tcsElapsedTime = tcs.ElapsedTime

UpTime (ReadOnly)

-- Returns an integer value indicating the total program up time in milliseconds.
tcsUpTime = tcs.UpTime




control

The control object provides access to the current control.



availability

In _update, _touch_down, _touch_move, and _touch_up scripts



methods

SetClip(int clipNumber)

-- Set the current control model's animation clip.
control:SetClip(0)


properties

AdjPosX

-- A float value containing the difference between the current and
--   start-up positions of the current model on the X axis.
adjPositionX = control.AdjPosX
control.AdjPosX = adjPositionX

AdjPosY

-- A float value containing the difference between the current and
--   start-up positions of the current model on the Y axis.
adjPositionY = control.AdjPosY
control.AdjPosY = adjPositionY

AdjPosZ

-- A float value containing the difference between the current and
--   start-up positions of the current model on the Z axis.
adjPositionZ = control.AdjPosZ
control.AdjPosZ = adjPositionZ

AdjRotX

-- A float value containing the difference between the current and
--   start-up rotations of the current model on the X axis.
adjRotationX = control.AdjRotX
control.AdjRotX = adjRotationX

AdjRotY

-- A float value containing the difference between the current and
--   start-up rotations of the current model on the Y axis.
adjRotationY = control.AdjRotY
control.AdjRotY = adjRotationY

AdjRotZ

-- A float value containing the difference between the current and
--   start-up rotations of the current model on the Z axis.
adjRotationZ = control.AdjRotZ
control.AdjRotZ = adjRotationZ

CustomProperties[string propertyName]

-- A collection of float variables shared with
--   custom HLSL vertex and pixel shaders.
control.CustomProperties["Glow_Amount"] = 1
glowAmount = control.CustomProperties["Glow_Amount"]

Movable

-- A bool value that toggles the ability to move a control in 3 dimensional space.
-- The default value is true.
canMove = control.Movable
control.Movable = false




setup

The setup object provides access to a set of methods used to set pre-initialization object properties.



availability

In screen _update scripts



methods

SetAmbientLight(float redIntensity, float greenIntensity, float blueIntensity)

-- Set the intensity of the screen's ambient light.
setup:SetAmbientLight(0.3, 0.3, 0.3)

SetControlModel(string controlName, string modelName)

-- Specify a control's model.
setup:SetControlModel("control_lightswitch1","lightswitch_model")

SetControlScale(string controlName, float scale)

-- Specify the scale of a control's dummy object.
-- A value of 100 = 100%.
setup:SetControlScale("control_lightswitch1",200)

UseParentScale(string controlName, bool useParentScale)

-- Models, by default, are scaled to match the size of
--   their parent control's dummy object.
-- Passing a false value to this method will disable automatic scaling.
setup:UseParentScale("control_lightswitch1",false)


< TCS Home