# Syntax of expressions in the blocks

To declare variables and set certain values ​​for them, the “[Variable Initialization](https://help.trikset.com/en/studio/blocks#variableinit)” block is used.

!["Variable Initialization" block](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-M51pe43V3dwgaNdg0_t%2F-M51qy1lrvlast0f4s2z%2FvariableInitBlock_100.png?alt=media\&token=44b8b583-fb8c-47d5-8d51-3f10c12b4353)

For mathematical expressions — "[Expression](https://help.trikset.com/en/studio/blocks#expression)" block.

!["Expression" block](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-M51pe43V3dwgaNdg0_t%2F-M51s0-8mn_MW1mdTryJ%2FfunctionBlock_100.png?alt=media\&token=81c18844-618a-4f8f-bfe4-ba1557f40bac)

Also, mathematical expressions, including those that change the values ​​of variables, can be used almost everywhere where you can specify a value.

Blocks and their properties that do not allow the use of mathematical expressions are described in the section ["Common blocks"](https://help.trikset.com/en/studio/blocks#list-of-common-blocks).

All variables in the program are global, i.e. their values ​​can be used in any block in the program.

## TRIK Studio language

The language used inside the blocks is based on [Lua 5.3](https://www.lua.org/) and largely follows its syntax. Nevertheless, there are significant differences, so a full description of the language used in TRIK Studio is given here.

* [Types](https://help.trikset.com/en/studio/programming-visual/expression-syntax/types)
* [Tokens](https://help.trikset.com/en/studio/programming-visual/expression-syntax/lexemes)
* [Operators](https://help.trikset.com/en/studio/programming-visual/expression-syntax/operators)
* [Sensor variables](https://help.trikset.com/en/studio/programming-visual/expression-syntax/sensory-variables)
* [Constants](https://help.trikset.com/en/studio/programming-visual/expression-syntax/const)
* [Built-in functions](https://help.trikset.com/en/studio/programming-visual/expression-syntax/built-in-functions)

## Examples of expressions

Declaration of several variables in one block "[Expression](https://help.trikset.com/en/studio/blocks#expression)":

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSi8SvZLH3_WbXP-fI-%2F-MSi8prlEwpC9EOocyTZ%2F18%201%20En%20Syntax1.png?alt=media\&token=309bb351-6867-403c-bd2f-a98770920d20)

The same using ["Variables Initialization" ](https://help.trikset.com/en/studio/blocks#variableinit)blocks:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSi8SvZLH3_WbXP-fI-%2F-MSi8t4nF2w9Xgt8Aoxo%2F18%202%20En%20Syntax2.png?alt=media\&token=10949e78-1387-4c9c-a213-8fb99f074f92)

Proportional controller for driving along the line using two light sensors for the TRIK platform:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSi8SvZLH3_WbXP-fI-%2F-MSi8wQewpjfPlGnAkFc%2F18%203%20En%20Syntax3.png?alt=media\&token=6bb5e493-891e-4e0b-82c3-ece1daf730dd)

An example of using [arrays](https://help.trikset.com/en/studio/programming-visual/expression-syntax/types/array) to set the ports of the “Motors forward” block. An array is created with the name `a`, the port `M3` is assigned to the zero element, the first is `M1`, then the contents of the first element of the array are changed to M4, then the resulting array is transferred to the “Ports” property of the “Motors forward” block:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSi8SvZLH3_WbXP-fI-%2F-MSi8zGGBZbIYvXgIY0b%2F18%204%20En%20Syntax4.png?alt=media\&token=816bd576-9b4f-4f7b-8a93-5e68aaf60e04)
