# Variables & Expressions

The ability to use variables within Studio greatly enhances flexibility in configuring interactivity for projects, enabling the creation of complex solutions and systems.

{% hint style="info" %}
This feature is currently in Beta as we actively refine the experience with variables and expressions. Despite ongoing improvements, it is already highly functional and enhances project capabilities significantly.
{% endhint %}

## What are Variables?

Vectary enables to create and manage variables that can be utilized across various Studio settings. These variables represent data elements such as numbers, text, or formulas, which can be created directly within Studio or imported from external sources like Google Sheets. A variable can store a specific value or use expressions to dynamically determine its value based on other parameters.

{% hint style="success" %}
Variables are also available for use in [Slider](https://open-2v.gitbook.com/url/help.vectary.com/documentation/3d-configurator/floating-ui/slider) and [Input](https://open-2v.gitbook.com/url/help.vectary.com/documentation/3d-configurator/floating-ui/input)
{% endhint %}

All variables are centralized for easy access and management:

{% embed url="<https://screen.studio/share/VKn4z6rw>" %}

{% hint style="info" %}
To delete or rename a variable, right-click on its name
{% endhint %}

## Expressions

Expressions provide a dynamic method for calculating parameter values using functions, binary operators, and variables.

This approach facilitates the creation of procedural effects and enables the implementation of complex solutions.

Most input fields in the UI support expressions (a detailed list can be found [here](https://open-2v.gitbook.com/url/help.vectary.com/documentation/3d-configurator/variables-and-expressions/list-of-inputs)), allowing for real-time modification of various settings, parameters, and text.

## Learn more

<table data-card-size="large" data-view="cards" data-full-width="false"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Syntax</strong></td><td><a href="variables-and-expressions/syntax">syntax</a></td><td><a href="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2Fz3YDqdZO67PQlAJd6Cgc%2FFrame%201.png?alt=media&#x26;token=3aff9244-cab3-4c1e-bd2b-d2509ad543b0">Frame 1.png</a></td></tr><tr><td><strong>Functions</strong></td><td><a href="variables-and-expressions/functions">functions</a></td><td><a href="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2Fz3YDqdZO67PQlAJd6Cgc%2FFrame%201.png?alt=media&#x26;token=3aff9244-cab3-4c1e-bd2b-d2509ad543b0">Frame 1.png</a></td></tr><tr><td><strong>List of inputs</strong></td><td><a href="variables-and-expressions/list-of-inputs">list-of-inputs</a></td><td><a href="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2Fz3YDqdZO67PQlAJd6Cgc%2FFrame%201.png?alt=media&#x26;token=3aff9244-cab3-4c1e-bd2b-d2509ad543b0">Frame 1.png</a></td></tr><tr><td><strong>Data import (.csv)</strong></td><td><a href="variables-and-expressions/data-import-.csv">data-import-.csv</a></td><td><a href="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2Fz3YDqdZO67PQlAJd6Cgc%2FFrame%201.png?alt=media&#x26;token=3aff9244-cab3-4c1e-bd2b-d2509ad543b0">Frame 1.png</a></td></tr></tbody></table>

## Example

Let's consider a simple example using **Variables** and **Expressions**.

**Task:** create a configuration that allows parametric changes to the length and width of the tabletop.<br>

{% stepper %}
{% step %}
Create a simple table using primitives

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FZ4iOiJsVBO9KVCjQI67z%2Fimage.png?alt=media&#x26;token=5c95e6f9-7624-46bb-bc6e-e4b4484848d9" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Create variables: **Width** and **Length**

Assign a value of 100 to each as the base size.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FFA6TIzTvtA8iydlucMhm%2Fimage.png?alt=media&#x26;token=aeba83c1-d37f-4c3e-9619-1e09be5cf04c" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Assign variables

Assign the created variables to the dimensions along the X and Y axes (replace the value with the variable name)

<div align="left"><figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2F0Wjm6rYiDSnb2iWJSeTs%2Fimage.png?alt=media&#x26;token=92664599-0740-43e4-8c9a-5948ff1076ef" alt="" width="323"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
Expression setup

To ensure the position of the table legs changes synchronously with the table dimensions, an **expression** using the **variable** must be assigned for the position value of each leg:

<table><thead><tr><th width="116.578125">Object</th><th width="137.34765625">X</th><th width="143.63671875">Y</th></tr></thead><tbody><tr><td>Leg 1</td><td><code>-width/2+5</code></td><td><code>-length/2+5</code></td></tr><tr><td>Leg 2</td><td><code>-width/2+5</code></td><td><code>length/2-5</code></td></tr><tr><td>Leg 3</td><td><code>width/2+5</code></td><td><code>length/2+5</code></td></tr><tr><td>Leg 4</td><td><code>width/2-5</code></td><td><code>-length/2+5</code></td></tr></tbody></table>

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FdWtQ5geZhQMHu2MffiHD%2Fimage.png?alt=media&#x26;token=f5fcbf0f-7e17-45ea-ad9d-59c80bb10901" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Add the **Floating UI**

Add the **Floating UI** to the scene and create a **Text** element along with a **Slider** element. The Text element will dynamically display the table size, while the **Slider** will be used to adjust the size.

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FZ5amrw55Oba3FGXHEa3y%2Fimage.png?alt=media&#x26;token=87e30ec9-aaee-46af-9fad-46faf0e0752f" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Setup **Text** element

Setup the **Text** element using an expression so that the table size is dynamically displayed based on the size selected by the end user.\
\
Use the following expression: "Width `${width}` "

<div align="left"><figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FoirhBZJb6DXZqIjx8V2S%2Fimage.png?alt=media&#x26;token=15ae54cf-3bbf-47ef-8a9b-3d62f4647e63" alt="" width="238"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
Setup the **Slider**

Setup the **Slider** element to allow the end user to adjust the dimensions of the table

Specify the variable **Width**, set the **Range** and **Step**:

<figure><img src="https://2973737105-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAXNLyKVZ2tvtyDr8sVES%2Fuploads%2FQB061EIzbAbLe9991oYL%2Fimage.png?alt=media&#x26;token=9adfb1e1-fbe7-4a82-b8f7-ba445e986d95" alt="" width="244"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
Repeat steps 6 and 7 for the length

**Done!** The Preview mode can now be activated to check the result:

{% embed url="<https://screen.studio/share/rZf6zWna>" %}
{% endstep %}
{% endstepper %}
