Scripting 5.2. Expressions

In a Praat script, you can use numeric expressions as well as string expressions.

## Numeric expressions

You can use a large variety of Formulas in your script:

`length = 10
` `height = length/2
` `area = length * height
` `writeInfoLine: “The area is ”, area, “.”
`

You can use numeric variables and formulas in numeric arguments to commands:

`Draw line: 0, 0, length / 2, 2 * height
`

You can use numeric expressions in assignments (as above), or after `if`, `elsif`, `while`, `until`, and twice after `for`.

## String expressions

You can use a large variety of Formulas in your script:

`addressee$ = “Silke”
` `greeting$ = “Hi ” + addressee$ + “!”
` `writeInfoLine: “The greeting is: ”, greeting$
`

You can use string variables and formulas in numeric arguments to commands:

`Draw line: 0, length (greeting$), 0, 100
` `Draw line: 0, if answer$ = “yes” then 20 else 30 fi, 0, 100
`

You can use numeric and string variables and formulas in string arguments to commands:

`Text top: “yes”, “Hi ” + addressee$ + “!”
` `Text top: “yes”, left$ (fileName$, index (fileName$, “.”) - 1)
`

## Assignments from query commands

On how to get information from commands that normally write to the Info window, see Scripting 6.3. Query commands.

### Links to this page

- Scripting
- Scripting 5. Language elements reference