# Data Types

## What is a data type?

A data type is a classification of, well, the type of data an object holds. For example, `"Hello, world!"` is a `string` (or `text`), and `1` is a `number` (more accurately, an `integer`).

{% hint style="info" %}
Data types in Skript include the common programming types: string, integer, number (Skript's version of float), and boolean, as well as some Minecraft-oriented types like player, item, block, and location.
{% endhint %}

Data types are important because otherwise things make no sense, for example, what if someone asked you to "please sit on this pizza and eat this chair"? What would you do?

See how absurd this request is? When someone hears the instruction "sit", they are going to expect a location to come next. Similarly, with the word "eat", they'll expect food.

This is what happens when asking Skript to run some code with incorrect data types. Skript can only perform mathematical operations with numbers, not blocks or items; that instruction would make no sense.

{% hint style="warning" %}
Using the wrong data type will result in an error, or the line simply failing.
{% endhint %}

***

## Detecting an object's datatype

Skript has a condition that can be used to check if an object is a target data type; `%object% is a %data type%`.\
-> Example: `if {_amount} is a number:`

SkBee also has a `class info` expression that can be used to get an object's data type.\
-> Syntax: `(class info of %object%|%object%'s class info)`

***

## Conversions

Here are some ways to convert to the correct data types.

### Locations

Consider this line: `teleport player to 1, 2, 3`. How is Skript supposed to teleport a player to a set of numbers? These numbers may be coordinates, but Skript doesn't know that. The `location()` function can be used to turn these into a location: `teleport player to location(1, 2, 3, world "world")`.

{% hint style="info" %}
The `location()` function's fourth parameter is the world; `world "%world name%"`. If left blank, this will default to `world "world"`.

The three default word names are `world`, `world_nether`, and `world_the_end`.
{% endhint %}

When checking for a block at a location, you'll need to convert one data type to the other:

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

```python
#: Either of these will work:
#: Get a location from the block
({_block}'s location) = {_location}

#: Get a block from the location
{_block} = (block at {_location})
```

{% endcode %}

{% hint style="warning" %}
Note that a block's yaw might be `180` or `-180` instead of `0`.

Adjust the location's yaw to account for this, or check if the distance between the block's location and the target location is negligibly small, such as `(distance between ({_block}'s location) and {_location}) < 1/100`.
{% endhint %}

### Players

The `player()` and `offlineplayer()` functions can be used to get a player from their UUID. The `player()` function is restricted to online players, but `offlineplayer()` is not, working for online and offline players.

{% hint style="info" %}
These should only be used when necessary (like getting a player from an index); try to store the player type itself when possible.
{% endhint %}

### Parsing

Strings can be parsed as other data types using the `parsed as` expression. For example, `"1" parsed as integer`, or `"baked potato" parsed as item`

{% hint style="warning" %}
Disclaimer: needless parsing eats up server resources, so if it can be avoided, it should. Thus, store and work with correct data types when possible.
{% endhint %}

***

## Clarification

Sometimes there's a bit of confusion between two similar data types:

{% tabs %}
{% tab title="Things with 'species'" %}

### Items & item type

Item = an actual item that exists somewhere (in a player's inventory, in a variable).

Item type = just the kind of item (like diamond sword).

### Entity & entity type

Entity = an entity that is actually on the server, referred to through an expression or variable.

Entity type = species of an entity, like the attacker is a zombie (not a specific zombie, just of the zombie species).

### Block & block data

Block data = the kind of block, like grass block.

Block = a block that exists placed in a world, referred to through a expression or variable (like this *individual* grass block the player is standing on).
{% endtab %}

{% tab title="Things with 'levels'" %}

### Potion effect & potion effect type

Potion effect type = the kind of potion effect (like poison).

Potion effect = a 'complete' potion with a tier and duration (like poison 5 for 10 seconds).

### Enchantment & enchantment type

Enchantment type = the kind of enchantment (like sharpness).

Enchantment = a 'complete' enchantment with a level (like sharpness 5).
{% endtab %}
{% endtabs %}


---

# 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/fundamentals/data-types.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.
