> For the complete documentation index, see [llms.txt](https://help.trikset.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.trikset.com/en/studio/programming-visual/expression-syntax.md).

# Syntax of expressions in the blocks

To declare variables and set certain values ​​for them, the “[Variable Initialization](/en/studio/programming-visual/blocks.md#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](/en/studio/programming-visual/blocks.md#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"](/en/studio/programming-visual/blocks.md#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](/en/studio/programming-visual/expression-syntax/types.md)
* [Tokens](/en/studio/programming-visual/expression-syntax/lexemes.md)
* [Operators](/en/studio/programming-visual/expression-syntax/operators.md)
* [Sensor variables](/en/studio/programming-visual/expression-syntax/sensory-variables.md)
* [Constants](/en/studio/programming-visual/expression-syntax/const.md)
* [Built-in functions](/en/studio/programming-visual/expression-syntax/built-in-functions.md)

## Examples of expressions

Declaration of several variables in one block "[Expression](/en/studio/programming-visual/blocks.md#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" ](/en/studio/programming-visual/blocks.md#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](/en/studio/programming-visual/expression-syntax/types/array.md) 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)
