# Variables

As a miscellaneous tool, this plugin supports internal variables. These variables can be set inside actions or through a command by admins and then used to check conditions inside tooltips.

Variables have a target, persistence and are defined through key-value pairs. For example, you can have a variable named "`meow`" equal to "`true`" or "`amount`" equal to `5`.



## Usage

Below is a reference table, which shows where and how variables can be used;



_If you want to modify variables, you can do it:_

* Inside tooltips' [actions](../configuration/preset/actions), using [variable commands](../configuration/preset/actions/commands)\
  For example:

```yaml
conditions:
  conditions:
  # When looking at a bedrock block
  - lookingatblock{type=bedrock} true
  actions:
    right-click:
    # And right clicking that bedrock block, set players variable "cool" to "true"
    - setvar %player% cool true
```

* Externally (outside of actions), using the [vars command](../../plugin/commands#variable-commands)\
  For example:\
  `/tt vars setvar Septicuss cool true`



_If you want to use variables in conditions (to check something)_

* Use the [compare condition ](../../configuration/preset/condition-list#compare)with [variable functions](../../configuration/preset/functions#usdvar-global-key-usdpvar-global-key)\
  For example:

```yaml
conditions:
  conditions:
  # Check if player has variable "cool" set to true
  - compare{ first=$var(cool); second=true }
```



_If you want to use variables in tooltips text_

* Use the [variable functions](../../configuration/preset/functions#usdvar-global-key-usdpvar-global-key)\
  For example:

```yaml
content:
  text:
  - 'Is the player viewing'
  - 'this tooltip cool?'
  - '$var(cool)'
```



_If you want to display variables outside of Tooltips in other plugins_

* Use [PlaceholderAPI variable placeholders](#placeholderapi)\
  For example:\
  `/papi parse Septicuss %tooltips_v_cool%`



## Terminology

### Persistence

There are persistent and non-persistent variables. Persistence means that variables are saved into files and kept around. Non-persistent variables are reset on server restart, persistent variables can only be cleared through the proper commands.&#x20;

### Scope

Variable commands define a scope, which defines who this variable will be set for.

| Scope           | Explanation                                                                                                                                   |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| Global          | A global variable applied to all players.                                                                                                     |
| Player          | The current player. For example, if this scope is used in actions, the action command will be executed for the player with an active tooltip. |
| \<Player\_Name> | An online players name. Using this will set it only for a specific player.                                                                    |

## Evaluation

Setting the variable supports mathematical expressions, which can utilize PAPI placeholders and local placeholders. Examples:

```
setvar player myvariable (1+1)
setvar global goofballs $var(global, goofballs) + 1
setvar global goofballs ($var(global, goofballs) / $var(myvariable)) * 30 + 25
/tt setpersistentvar Septicuss personal_number 31*5
```





## PlaceholderAPI

Using PlaceholderAPI placeholders has been made as simple as possible. Placeholders are dynamic, and you have to build them using keys:

<table><thead><tr><th width="180">Key</th><th>Description</th></tr></thead><tbody><tr><td>v</td><td>variable (always required)</td></tr><tr><td>g</td><td>global</td></tr><tr><td>p</td><td>persistent</td></tr></tbody></table>

#### Structure of a placeholder

`%tooltips_[KEY]_[ID]%`

\[KEY] -> multiple keys combined in any order

\[ID] -> ID of the variable being requested

#### Examples

_Get the player variable "cool"_

`%tooltips_v_cool%`

_Get the global variable "cool"_

`%tooltips_gv_cool%`

_Get the **persistent** player variable "tutorial\_passed"_

`%tooltips_pv_tutorial_passed%`

_Get the **persistent** global variable "views"_

`%tooltips_pgv_views%`





