> 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/en/start/lifecycle.md).

# How a script is built

Callbacks, script states and the methods you can call from the class.

A loaded script is not necessarily running. The constructor runs when the jar is loaded, and that is where settings are created. Callbacks, subscriptions, commands and hotkeys work only while the script is enabled. When the script is disabled, Quick removes its subscriptions, tasks and commands, and the next time it is enabled Quick calls `activate()` again.

```java
public class Pinger extends Script {

    @Override
    public void activate() {
        on("tick", event -> tick());
        command("ping").runs(context -> context.reply(client().ping() + " ms")).register();
    }

    @Override
    public void deactivate() {
        log().info("script disabled");
    }

    private void tick() {
        if (client().ping() > 300) notifications().warning("high ping: " + client().ping(), 1500L);
    }
}
```

## How it works

* In `activate()` the script subscribes to the tick and registers the `ping` command. When the script is disabled, both the subscription and the command are removed.
* Every tick the script checks the ping and shows a notification if it is above 300.
* `deactivate()` only writes a line to the console. You do not need to remove subscriptions manually.

## Callbacks

| Method                 | When it is called                                                                |
| ---------------------- | -------------------------------------------------------------------------------- |
| constructor            | once when the jar is loaded; create settings, fonts, shaders and meshes here     |
| `activate()`           | on enable; reset state and subscribe with `on(…)` and `hook(…)` here             |
| `deactivate()`         | on disable, before a reload and on exit; you do not need to remove subscriptions |
| `onTick()`             | game tick, 20 times per second, while the script is enabled                      |
| `onRender2D(Render2D)` | every frame on top of the game, see [2D render](/en/ui/render-2d.md)             |
| `onRender3D(Render3D)` | every frame while you are in a world, see [3D render](/en/ui/render-3d.md)       |

All callbacks run on the game's main thread. Long operations in them make the game stutter. It is better to do heavy calculations in advance and store the result in a field.

If a callback throws an exception, the game does not crash. The script is disabled, and the console shows a line saying that the script was turned off and why. Until the next reload the script is marked as crashed.

## Available methods

All methods in the table below are protected methods of `Script`, so you can call them by name. Outside a world, methods related to the world return zeros and empty strings instead of throwing an exception.

| Method            | Type            | What it is                                                                                 |
| ----------------- | --------------- | ------------------------------------------------------------------------------------------ |
| `player()`        | `Player`        | your own player, see [Your player](/en/game/player.md)                                     |
| `inventory()`     | `Inventory`     | inventory, see [Inventory and items](/en/game/inventory.md)                                |
| `world()`         | `World`         | blocks, weather, time, see [World and blocks](/en/game/world.md)                           |
| `entities()`      | `Entities`      | entities, target, crosshair, see [Entities](/en/game/entities.md)                          |
| `container()`     | `Container`     | the open chest or menu, see [Containers and screens](/en/game/containers.md)               |
| `tab()`           | `Tab`           | player list and teams, see [Server, scoreboard, tab list](/en/game/server.md)              |
| `scoreboard()`    | `Scoreboard`    | the sidebar scoreboard, same page                                                          |
| `client()`        | `ClientInfo`    | fps, ping, tps, name, server, effects, screen, same page and [Account](/en/extras/user.md) |
| `party()`         | `Party`         | party in Quick, see [Party](/en/extras/party.md)                                           |
| `control()`       | `Control`       | sprint, sneak, jump, speed, camera, see [Movement](/en/actions/control.md)                 |
| `keys()`          | `Keys`          | which keys are held right now, see [Keys and binds](/en/actions/keys.md)                   |
| `interaction()`   | `Interaction`   | attacks, using items, blocks, see [Interaction](/en/actions/interaction.md)                |
| `slots()`         | `Slots`         | held slot, armor, see [Slots and armor](/en/actions/slots.md)                              |
| `rotations()`     | `Rotations`     | head rotations, see [Rotations](/en/actions/rotations.md)                                  |
| `prediction()`    | `Prediction`    | where the player and projectiles will go, see [Prediction](/en/actions/prediction.md)      |
| `packets()`       | `Packets`       | building and sending packets, see [Packets](/en/actions/packets.md)                        |
| `fonts()`         | `FontRegistry`  | fonts, see [Styled text](/en/ui/text.md)                                                   |
| `gpu()`           | `Gpu`           | your own meshes, see [Your own geometry](/en/ui/gpu.md)                                    |
| `shaders()`       | `Shaders`       | your own GLSL shaders, see [Shaders](/en/ui/shaders.md)                                    |
| `chat()`          | `Chat`          | a message to your own chat or to the server, see [Messages](/en/ui/messages.md)            |
| `chat(String)`    | `void`          | a quick message to your own chat                                                           |
| `log()`           | `Log`           | script console, same page                                                                  |
| `notifications()` | `Notifications` | pop-up notifications, same page                                                            |
| `clipboard()`     | `Clipboard`     | clipboard, same page                                                                       |
| `sounds()`        | `Sounds`        | sounds only you can hear, see [Sounds and particles](/en/extras/effects.md)                |
| `particles()`     | `Particles`     | particles only you can see, same page                                                      |
| `waypoints()`     | `Waypoints`     | map markers, see [Waypoints](/en/extras/waypoints.md)                                      |
| `storage()`       | `Storage`       | the script config, see [Saving data](/en/settings/storage.md)                              |
| `storage(name)`   | `Storage`       | a config with the given name                                                               |
| `tasks()`         | `Tasks`         | timers, see [Timers and tasks](/en/extras/tasks.md)                                        |
| `assets()`        | `Assets`        | files from `resources/`, see [The assets folder](/en/extras/assets.md)                     |
| `command(name)`   | `Command`       | your own command, see [Your own commands](/en/extras/commands.md)                          |
| `hook(name, h)`   | `void`          | a response to a call from a mixin, see [Mixins and hooks](/en/extras/mixins.md)            |
| `modules()`       | `ModuleInfo[]`  | Quick modules at the time of the call, see [Client modules](/en/extras/modules.md)         |
| `settings()`      | `List<Setting>` | all script settings in creation order                                                      |
| `eventNames()`    | `String[]`      | which events your Quick build knows, see [Event list](/en/events/reference.md)             |
| `target()`        | `Object`        | deprecated, use `entities().target()`                                                      |

## Enabled, disabled, crashed

* **Disabled:** the code does not run, but the settings are visible and can be changed.
* **Enabled:** callbacks, subscriptions, commands and hotkeys work.
* **Crashed:** a callback threw an exception. The script is disabled until the next reload, and its row in the list is red.
* **Restart required:** the mixins in the jar differ from the ones loaded when the game started. The script itself works, but the mixins are still the old ones.

The state is kept after a script reload and after a game restart.

## API version

`Script.API_VERSION` shows the SDK version the script was built with. If it does not match the version in Quick, see [API versions](/en/extras/api-versions.md).


---

# 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/en/start/lifecycle.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.
