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.