# Deleting Variables

Sometimes you don't need to keep your variables long term, and they can be deleted when a player leaves or they aren't currently in use. No matter how fancy your server or how much you pay, you'll have a finite amount of storage space.

Deleting data can seem scary, but don't worry—you don't have to delete anything important. Just the things that have served their purpose, things you don't need anymore. This will make your `variables.csv` (and any other databases) much tidier. When Skript is overloaded with too many variables, it can start to crash or give severe errors.

Example 1:

When you have a toggle for something, instead of setting a variable to `false`, simply delete it.

{% hint style="success" %}
To check if the toggle is disabled in this new code, instead of checking for `false`, check for `not set`.
{% endhint %}

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

```python
command combatToggle:
  alases: combat, pvpToggle, pvp
  permission: combat.toggle
  trigger:
    if any:
      {combat} = false
      {combat} is not set
    then:
      set {combat} to true
      broadcast "Combat has been enabled!"
      
    else:
      set {combat} to false
      broadcast "Combat has been disabled!"
```

{% endcode %}

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

```python
command combatToggle:
  alases: combat, pvpToggle, pvp
  permission: combat.toggle
  trigger:
    if {combat} is not set:
      set {combat} to true
      broadcast "Combat has been enabled!"
  
    else:
      delete {combat}
      broadcast "Combat has been disabled!"
```

{% endcode %}

Now, `{combat}` doesn't sit around taking up storage space. And, as a cherry on top, the code was shortened a bit!

{% hint style="info" %}
When sending `{combat}`, you can give it a default value: `{combat} (?|otherwise) false` will be `{combat}`'s value if `{combat}` is set, and `false` otherwise.
{% endhint %}

One variable might not seem like a lot, but if you do this diligently it can add up.

This issue is also often seen when working with player-specific variables, meaning there's one useless variable per player, which quickly escalates.

Example 2:

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

```python
command nightVision:
  aliases: nv, fullBright, fb
  trigger:
    if any:
      {nightVision::%executor's UUID%} = false
      {nightVision::%executor's UUID%} is not set
    then:
      set {nightVision::%executor's UUID%} to true
      apply infinite night vision without particles without the icon to executor
      send "You have enabled night vision!" to executor

    else:
      set {nightVision::%executor's UUID%} to false
      remove night vision from executor
      send "You have disabled night vision!" to executor
```

{% endcode %}

While this is completely functional, you must face the truth: players leave your server, sometimes never to return. When this happens, their `nightVision` variable is just sitting there not being used *and* taking up space. Even if they come back, when set to `false`, the variable still exists.

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

```python
command nightVision:
  aliases: nv, fullBright, fb
  trigger:
    if {nightVision::%executor's UUID%} is not set:
      set {nightVision::%executor's UUID%} to true
      apply infinite night vision without particles without the icon to executor
      send "You have enabled night vision!" to executor

    else:
      delete {nightVision::%executor's UUID%}
      remove night vision from executor
      send "You have disabled night vision!" to executor
```

{% endcode %}

However, a player could still leave the server without disabling their night vision, so you just have to disable it for them:

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

```python
on quit:
  delete {nightVision::%player's UUID%}
```

{% endcode %}

***

## Alternatives

Attentive readers may have noticed that the `nightVision` variable could be changed to a metadata tag. Or, perhaps conditions could be used to check if the player has night vision in their active potion effects. Both of these are excellent alternatives to having a variable.

Variables, while the most common storage device, are not the only option. There are other forms of data storage that have advantages and are cleaner.

{% hint style="info" %}
For other storage options and their attributes, see the [Alternatives section on the Variables page](/syntask/storage/variables.md#alternatives).
{% endhint %}


---

# 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/deleting-variables.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.
