# SLIDE Tcl Basics Tutorial

## TCL

### Basic *TCL* Expressions

*TCL* Math

A *TCL* math expression is written:

`expr `*math*

For example,

`expr (30 * sin(100)) + $SLF_MOUSE_X`

You can use any of the basic math operators: (+, -, *, /), as well as
shift operators: (<<, >>), bit operators: (&, |), math functions:
(`sin, cos, tan, atan, asin, acos, atan2, exp, log`

).
Pretty much any math you can do in C, you can do in *TCL*.
The only thing that works much differently is arrays and array
indexing, which uses lists.
This should be all you need to know to design a dynamic scene. If you
want to explore all the power of *TCL*, you can use your own variables,
functions, and even widgets, but simple mathematical expressions
should be sufficient to create interesting behaviors in your *SLIDE* scene.

*TCL* Variables

You can create a variable or set the value of an existing variable
with the `set`

command:

`set `*variable* *value*

For example,

`set x 30`

When you want to get the value of a variable in an expression, prepend
a "$" to the variable name. So `$y`

gets the value of the
variable `y`

.

`set z $y`

Square brackets force evaluation of a statement, whereas curly
braces pass the statement along unevaluated as a list, so

`set y [expr 10 * 100]`

gives the variable `y`

the value 1000, whereas

`set y {expr 10 * 100}`

gives the variable `y`

the list value {expr, 10, *, 100}.

*TCL* Lists (Vectors)

You can write a list of constant values with curly braces:

`set v {1 2 3}`

If your list contains an expression that needs to be evaluated, you
need to use the `list`

statement:

`set v [list 1 2 [expr sin(30)]]`

You can access individual members of a list with `lindex`

(short for listindex), so with `v`

defined as above:

`lindex $v 0`

has value 1, and

`lindex $v 1`

has value 2, and

`lindex $v 2`

has value `sin(30)`

or 0.5.
#### Testing Your *TCL* Expressions

If you want to test out *TCL* expressions, run `wish`

and
type in *TCL* expressions at the command prompt.
You may want to start out by defining those *SLIDE* variables that you
will expect to find with some arbitrary value:

```
set SLF_TIME 1
```

set SLF_MOUSE_X 100

set SLF_MOUSE_Y 300

You can check the value of any variable with the command,
`puts`

(short for putstring).

`puts $y`

You can input a file of *TCL* commands with the `source`

command:

`source my_commands.tcl`

This page was originally built by Jordan Smith.

Last modified: **Saturday, 06-Feb-1999 23:50:03 PST**