# Conditions

## Introduction

Conditions are defined per [preset](/tooltips/configuration/preset.md) and allow to control when a preset is displayed to the player. For a preset to be shown, all of its conditions must be evaluated to true.

```yaml
conditions:
# If players game mode is either creative or survival
- gamemode {gm=creative, survival} true
# If the player is looking at a grass block
- lookingatblock {type=grass_block}
```

When conditions are checked, they are checked line by line. The above example would first check if the players gamemode is either creative or survival after which it would check if the player is also looking at a grass block.

### Structure

The structure of a singular condition is really simple. It consists of just two parts; the conditions name and its possible arguments inside of curly brackets ( {} ):

```
condition_name { key: value ; key: value }
```

**All argument types are covered here:**

{% content-ref url="/pages/uTa7COjjZMcu4ZGQsiY8" %}
[Argument Types](/tooltips/configuration/preset/argument-types.md)
{% endcontent-ref %}

If a condition does not have any required arguments, it can be defined without the curly brackets like so:

```yaml
conditions:
- night
- day
```

**All conditions are covered here:**

{% content-ref url="/pages/RylgDsiKMQX4ruNZYPLp" %}
[Condition list](/tooltips/configuration/preset/condition-list.md)
{% endcontent-ref %}

## Outcomes

An important part of optimizing conditions, is the ability to stop reading conditions early if some condition is false. For example, all operations that start with "lookingat" are expensive to perform, so it's imperative that they aren't checked often. This can be done using outcomes.

Outcomes are optional and defined at the end of a full condition like so:

```
- <condition> (outcome)
```

### Supported outcomes

<table><thead><tr><th width="217">Outcome</th><th>Description</th></tr></thead><tbody><tr><td>required (or true)</td><td>The current line must be true. If it isn't, further conditions won't be checked.</td></tr><tr><td>cancel (or false)</td><td>If the current line is true, further conditions won't be checked. </td></tr><tr><td>skip</td><td>Skips the condition (does not check it), but still writes <strong>context</strong></td></tr></tbody></table>

### Examples

If we wanted to check if player is looking at furniture inside of a WorldGuard region called "shop", we'd put the region condition first and give it the "required" outcome:

```yaml
conditions:
# If players region is "shop"
- region { r = shop } required
# If player is looking at any type of furniture
- lookingatfurniture required

```

This way, the region condition will be performed first and only when it is true, will the "lookingatfurniture" run.

## Context

Many conditions return context, which contains useful information about the target. For example, a `time` condition may return the current time in ticks or `lookingatfurniture` condition may return the name of the furniture. The context returned by conditions is documented in the [condition list](/tooltips/configuration/preset/condition-list.md).

Conditions only return context if they are `true` or if the outcome is marked as "`skip`".

Context can be used with the [`$context(key)`](/tooltips/configuration/preset/functions.md#usdcontext-key) function.

## Composite conditions

Composite conditions allow you to do more complex logical checks in a single line using operators.

### Supported operators

<table><thead><tr><th width="229">Operator</th><th>Description</th></tr></thead><tbody><tr><td>AND ( also &#x26;&#x26; )</td><td>Left and right part must both be true</td></tr><tr><td>OR ( also  || )</td><td>Left or right part must be true</td></tr></tbody></table>

### Examples

```yaml
conditions:
# If the region is shop AND players gamemode is creative
- region { r = shop } AND gamemode { gm = creative } true
# If player is looking at any type of furniture or at any type of entity
- lookingatfurniture || lookingatentity
```

Even more extreme example, when operators are combined with parenthesis:

{% code fullWidth="false" %}

```yaml
conditions:
# (If the region is shop) AND ( (player is either looking at a coach) OR (is in creative) )
- ( region {r = shop } ) AND (lookingatfurniture { id = coach } OR gamemode { gm = creative } )
```

{% endcode %}


---

# 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://tooltips.gitbook.io/tooltips/configuration/preset/conditions.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.
