Skip to main content
Version: 25.1

Planning Your Route – Commands and Functions

You won't get anywhere in the SenseTalk landscape without Commands and Functions. We'll cover the important parts here, but for more information see Commands and Functions in the SenseTalk Reference guide.

Commands

Commands come in two forms: built-in commands with a custom syntax (like put 7 into x); and generic commands. Generic commands can be used to call your own scripts or handlers. The generic command syntax is a single word (the command), optionally followed by one or more parameters separated by commas, with NO PARENTHESES:

myCommand p1,p2,p3
myOtherCommand
Survival Tip

Commands are not Functions

In SenseTalk each statement is a command. Parameters passed to a command are not enclosed in parentheses.

myCommand param1, param2, param3

If you use parentheses around values passed to a command, the values in parentheses are interpreted to be a list, which is then passed as a single parameter to the command.

For more information, see Commands and Comments

Functions

A function call occurs in the context of an expression, where a value is expected. Functions can be used to call your own scripts or handlers. Functions can be called in multiple ways:

put seed(p1,p2,p3) -- traditional function syntax with parameters
put seed() -- traditional function syntax with no parameters
put the seed -- English-like syntax with no parameters ('the' is required in this case)
put the seed of p -- English-like syntax with 1 parameter ('the' is optional with 'of')
put p.seed -- dot syntax with 1 parameter
put p's seed -- possessive syntax with 1 parameter

Note that the of, dot, and possessive syntaxes can also be used to access a property of an object.

Messages and Handlers

SenseTalk is a message-based language. Commands send command messages and function calls send function messages, which can both be handled by a script or "message handler" with a matching name.

note

Terminology: For this reason, procedures in SenseTalk are called "handlers" rather than "functions" or "methods".

There are 3 types of handlers. Normally, you should just write to (or to handle) handlers, which can handle either command or function messages. If needed, you can also write on handlers which will only handle a command message, or function handlers which will only handle a function message.

A script is treated as a to handler, which can handle either a command or function call with the same name as the script. When a script is called, SenseTalk executes the "initial handler" of the script. The initial handler consists of all of the lines of code from the beginning of the script until the first explicit handler in the script (beginning with to, on, or function), or the entire script if it doesn't contain any explicit handlers.

note

Any lines between handlers, or after the final handler, are ignored and never executed.

For more information, see Messages and Handlers.