> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/extras/tasks.md).

# Таймеры и задачи

Отложенные и повторяющиеся задачи скрипта, которые выполняются в потоке игры.

`tasks()` это планировщик скрипта. Он нужен, когда действие надо выполнить через некоторое время или повторять с периодом. Время отсчитывает сам Quick, а задачи выполняются в потоке игры, поэтому из них можно работать с миром и рендером. Когда скрипт выключается, все его задачи снимаются автоматически.

```java
tasks().after(500L, () -> chat("прошло полсекунды"));
int id = tasks().every(1000L, () -> chat("ещё секунда"));
tasks().cancel(id);
```

`after`, `every`, `repeat` и `soon` возвращают id задачи, по которому её можно снять через `cancel`.

| Метод                         | Тип       | Описание                                      |
| ----------------------------- | --------- | --------------------------------------------- |
| `after(millis, body)`         | `int`     | один раз после задержки                       |
| `every(millis, body)`         | `int`     | бесконечно с периодом                         |
| `repeat(millis, times, body)` | `int`     | `times` раз с периодом                        |
| `soon(body)`                  | `int`     | один раз на ближайшем кадре                   |
| `cancel(id)`                  | `boolean` | снимает задачу                                |
| `cancelAll()`                 | `int`     | снимает все задачи и возвращает их количество |

Время указывается в миллисекундах реального времени, а не в тиках. Если сервер лагает, период не растягивается. Если нужен отсчёт в тиках, считайте их в `onTick()`, как в [Первом скрипте](/start/first-script.md).

Если задача выбросила исключение, происходит то же, что и в любом колбэке: скрипт выключается, а причина пишется в консоль.

Собственных потоков у скрипта нет: `Thread` и `java.util.concurrent` закрыты. Фоновую работу нужно делать задачами или по тикам.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.quickclient.cc/extras/tasks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
