When a script is executed, the statements in the script are normally executed one at a time, in the order they appear in the script. The information presented here explains about control structures and commands and how they may conditionally alter the basic flow of execution.
Control structures form the foundation of a script. They define the basic framework that lets you create handlers, declare global and universal variables, and control the execution of your script through conditional statements and repeat loops, among other things. They also provide control over the flow of messages through the system.
In addition to the control structures presented here, another important part of structuring scripts is the use of handlers to deal with different messages. Handlers are presented in Objects and Messages.
Using Script Structure and Control Flow
To understand how to use control structures and commands to alter the basic flow of execution, see the following topics:
Statements and Comments: A SenseTalk script is a sequence of statements or commands that contain your instructions. Each statement is typed on a separate line, in the form of an imperative command that begins with a verb. Comments may be introduced into a script at any point, to provide notes to the reader or developer of the script. Read more detailed information here about using statements and comments.
Conditional Statements: Conditional statements let your script make choices, carrying out some actions only under certain conditions, and other actions under other conditions. Read more detailed information here about using conditional statements.
Repeat Loops: One of the great strengths of computers is their ability to perform repetitive tasks with ease. SenseTalk provides several different types of repeat loops for this purpose. Read more detailed information here about using repeat loops.
Flow Control: There are a number of statements that can affect the flow of statement execution within a loop. Read more detailed information here about using these statements.
Handlers: An object has a script, which has handlers. The object must have access to a handler for a particular message in order to receive that message and act on it. Read more detailed information here about using handlers.
Running Other Scripts and Handlers: The simplest way to run another script is to use the name of that script as a command, along with any needed parameters. Read more detailed information here about using the name of a script as a command.
Parameters and Results: Parameters are values that are passed to commands or functions. Read more detailed information here about passing parameters to commands or functions.
Pausing Script Execution: Script execution can be paused, either to wait for some external condition, or to delay for a specified length of time, using one of the wait statements. Read more detailed information here about using a wait statement to pause script execution.
Error handling: During script execution, errors may occur. Read more detailed information here about handling errors that occur during script execution.
Declaring Global and Universal Variables: You can uses a global statement to declare global variables and a universal statement to declare universal variables. Read more detailed information here about using these declarations.