# List Variables (Arrays)

Lists (also called arrays in other languages) will have indicies (or keys) and values, similar to Python's dictionaries. However, one key difference is that in Skript, indicies are *stringified*, meaning they become a string. This makes getting values from indices a little pesky.

***

## List Variables

The list variable separator, `::`, turns a standard variable into a list variable by adding a space for an index.

An index is a position or key that corresponds to the value of an element in a list. They go after the list separator and are used to access a specific object stored in a list variable.

{% hint style="info" %}
Sometimes, people will use `.` in variables; `{balance.%player's UUID%}`. However, this ***does not*** make the UUID an index like `::` would: `{balance::%player's UUID%}`.

This means Skript treats `{balance.%player's UUID%}` as a variable named `balance.1234...`, and not as an element in the list `balance` with an index or key of `1234...`.

{% hint style="warning" %}
The `.` character has no place in variable names. Either use the double-colon list separator `::` to make the variable a list, or if you don't want to use a list, name the variable using camel case, kebab case, or snake case.
{% endhint %}

Using a list instead of multiple *un-linked* variables makes everything much easier to manage, and opens up the possibilites to loop through balances, or delete all balances at once.
{% endhint %}

When you set a list variable to a bunch of objects, Skript will create numbered indices:

{% code overflow="wrap" lineNumbers="true" %}

```python
set {exampleList::*} to ("a", "b", "c", and "d")
broadcast {exampleList::1} #: "a"
broadcast {exampleList::2} #: "b"
broadcast {exampleList::3} #: "c"
broadcast {exampleList::4} #: "d"
```

{% endcode %}

{% hint style="warning" %}
Note that indices Skript are not zero-indexed, meaning they start at `1` and do not start at `0`. This is unfortunate, as most other languages (and even Minecraft inventories) are zero-indexed.
{% endhint %}

{% hint style="info" %}
The asterisk (`*`) is a special symbol that basically means "everything", or in this case "all indices", which allows for accessing everything in the list at once.

An index is used to grab a specific element from a list (getting or setting an element), otherwise the asterisk is used to refer to the whole list (looping, sorting, etc.).
{% endhint %}

Specifying an index 'targets' a specific element in the list, as shown above. Choosing `1`, `2`, `3`, or `4` as an index will access the letters `a`, `b`, `c`, and `d` respectively.

Using the `add` effect also will automatically assign a numbered index, `add "z" or {exampleList::*}` will set `{exampleList::n}` to `"z"`, where `n` is the lowest positive integer that is not already being used as an index. If we were to add to the list above, the next index would be `5`, then `6`, and so on.

{% hint style="info" %}
However, if you were to delete or remove an element, that will also free up an index.

For example,&#x20;

{% code overflow="wrap" lineNumbers="true" %}

```python
set {exampleList::*} to ("a", "b", "c", and "d")

#: Either of these two lines make an index of 3 not used
delete {exampleList::3}
remove "c" from {exampleList::*}

add "e" to {exampleList::3}
```

{% endcode %}

Now since `3` is no longer identifying anything in the list, when `e` is added `3` was the lowest possible index (`1` and `2` are still used), so `{exampleList::3}` becomes `e`.
{% endhint %}

### Naming indices

Most of the time, it's easiest to name the indices to keep track of elements in a list. To specify a name for an index, you'll need to assign a value individually, `set {list::yourCusomIndexHere} to something`.&#x20;

{% hint style="warning" %}
Just remember that *indices are stringified in Skript*, so you'll need to use `%` around non-literals.

Bad: `set {balance::player's UUID} to 10` (Index is the literal `"player's UUID"`)\
Good: `set {balance::%player's UUID%} to 10` (Index is `"1234..."`; their UUID)
{% endhint %}

Now, when you want to get a specific player's balance, you can just pass their UUID into the list as an index!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x8ight.gitbook.io/syntask/storage/variables/list-variables-arrays.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
