First t Script

Now that we better understand the layout of TRX, let’s make our first t script. To begin, we’ll need an on-event hook or “event hook” for short. Put simply, these are functions that state, “on the occurrence of an event, we would like to take an action.” Thus, an on-event hook acts much like a fishing hook, waiting for the moment it receives a catch before acting. And when that event occurs, the t script will go right to work, performing the actions laid out in the event hook.

For our first script, let’s start with the on start event hook. This event hook will activate when our t script starts. Now that we know which event we will be acting on, we need our action that we want the script to perform. For our action, let’s take the classic standby example of a quick “hello world” print statement. If this is your first time writing code, then allow us to welcome you to the long-standing tradition in software development of the “hello world example.” Now, let’s take a look at our code.

on start {
      printf(“Hello World!\n”);
}

First, there is the on start event hook. Within the braces of the event hook, we have defined the actions that should be taken when the event hook is triggered. When our t script starts, the on start event hook will trigger, printing the text string, “Hello World!” with \n instructing the function to then print a newline so the next console output will be on its own line; our semi-colon acting as a period, informing the program where the end of the statement is.

Press Start  from the list of buttons above the code editing window in TRX and, assuming your t-compatible device is plugged into your PC and a channel is selected in the drop-down menu, in the Device Output window below you should see the output, “Hello World!” Congratulations! You’ve written your first tscript.

Lesson tags: t script, TRX

First t Script Quiz

Please sign up for the course before taking this quiz.
  1. 1. An on-event hook is essentially a function that states:

  2. 2. The semi-colon acts as a _____ informing the program where the _____ of a statement is.

Back to: <em>t</em> Scripting > Getting Started