> For the complete documentation index, see [llms.txt](https://stage-precision.gitbook.io/grid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stage-precision.gitbook.io/grid/scripting/data-types-and-valuetree.md).

# Data Types & ValueTree

### Standard Python Data Types

Because Grid Studio uses Python, standard Python data types can be used throughout scripts.

Common types include:

* `bool`
* `int`
* `float`
* `str`
* `list`
* `tuple`
* `dict`

For example:

```python
enabled = True
count = 5
distance = 2.5
name = "Camera"
position = [0, 1, 2]
```

The type of value returned by a Grid Studio Parameter depends on that Parameter's data type.

### Grid Studio Data Types

Some Grid Studio Parameters use multi-value data types that are represented as Python lists when accessed from a script.

#### Point

A Point contains two values:

```python
[x, y]
```

For example:

```python
point = [0.5, 1.0]
```

Individual values can be accessed by index:

```python
x = point[0]
y = point[1]
```

#### Vector

A Vector contains three values:

```python
[x, y, z]
```

For example:

```python
position = [0.0, 1.0, 2.5]
```

Individual components can be accessed using normal Python list indexing:

```python
x = position[0]
y = position[1]
z = position[2]
```

This is the same structure returned by Vector Parameters such as:

```python
position = sp.Tracker1.coordinates.position.value
```

#### Color

A Color contains four values:

```python
[red, green, blue, alpha]
```

The values are represented as floats.

For example, red with full opacity can be represented as:

```python
[1.0, 0.0, 0.0, 1.0]
```

Individual Color components can also be accessed using their list index:

```python
red = color[0]
green = color[1]
blue = color[2]
alpha = color[3]
```

{% hint style="info" %}
Point, Vector and Color values can be handled using normal Python list operations such as indexing and assignment.
{% endhint %}

### Lists and Indexed Values

Parameters containing multiple values can be accessed using normal Python list indexing.

For example, a Position Parameter returns its individual components through `.value`:

```python
position = sp.Tracker1.coordinates.position.value

print(position[0])
print(position[1])
print(position[2])
```

Individual elements can also be referenced directly:

```python
sp.Tracker1.coordinates.position.value[0]
```

This can be useful when only one part of a multi-value Parameter is required.

### Parameter Values

When accessing a Parameter, `.value` returns its current value.

For example:

```python
position = sp.Tracker1.coordinates.position.value
```

A value can also be assigned using the corresponding Python data type:

```python
sp.Tracker1.coordinates.position.value = [0, 1, 2]
```

The assigned value must be compatible with the Parameter being controlled.

{% hint style="info" %}
Without `.value`, the reference points to the Parameter itself rather than its current value.
{% endhint %}

### ValueTree

`sp.ValueTree` is a Grid Studio data structure for working with structured data.

A new ValueTree can be created using:

```python
result = sp.ValueTree("root")
```

Values can then be added to the tree:

```python
result["someData"].value = 1
```

ValueTrees are particularly useful when scripts need to pass structured data between different parts of Grid Studio.

### ValueTree in Workflow Script Actions

Workflow Script Actions can use a ValueTree to return data back into the Workflow.

For example:

```python
def action(data, callback):
    result = sp.ValueTree("root")
    result["someData"].value = 1

    callback(result, False, 0, True)
```

The returned ValueTree becomes available as data to following Actions in the Workflow.

This allows a Script Action to return structured information instead of being limited to a single simple value.

### Working with Larger Data Structures

ValueTrees can be used when scripts need to work with larger or multi-layered data structures.

This is useful for data that contains multiple related values or needs to be passed between different processing stages.

For simple calculations and temporary values inside a script, standard Python types such as lists, dictionaries or numbers are usually sufficient.

`sp.ValueTree` provides a Grid Studio-native structure for hierarchical data and can be used when structured data needs to be passed through Grid Studio.

{% hint style="info" %}
Workflow Script Actions can return either a standard Python `dict` or an `sp.ValueTree` through `callback()`.
{% endhint %}

### Next Steps

See **Script Editor & Debugging** to learn about the integrated Script Editor, autocomplete, logging and Visual Studio Code integration.
