---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/hi/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/ko/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/ru/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/tr/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/vi/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/zh/sdk/defold/events.md
  - href: vi/sdk/defold/events.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/vi/llms.txt

# Sự kiện

Bạn có thể theo dõi các sự kiện xảy ra khi người dùng nhấn vào các nút nhất định trong trò chơi.

Các sự kiện và phương thức có sẵn để làm việc với chúng:

```lua
ysdk = {
  on_event = function (eventName: "EXIT" | "HISTORY_BACK", listener: function): nil,
  dispatch_event = function (eventName: "EXIT" | "HISTORY_BACK", detail: table|nil): nil,
}
```

## HISTORY_BACK

Để theo dõi việc nhấp chuột vào nút **Quay lại**, hãy sử dụng phương thức sau:

```lua
ysdk.on_event("HISTORY_BACK", function (self)
    -- Hiển thị hộp thoại trò chơi tùy chỉnh cho người dùng với các tùy chọn
    -- để xác nhận thoát khỏi trò chơi, chuyển đến cài đặt nội bộ, cửa hàng, v.v
end)
```

{% note alert "Hạn chế" %}

Sự kiện chỉ khả dụng khi trò chơi được chạy trên TV.

{% endnote %}

## EXIT

Nếu người dùng xác nhận thoát khỏi trò chơi trong hộp thoại tùy chỉnh bật lên sau khi nhấp vào **Quay lại**, trò chơi phải gửi sự kiện thoát. Để thực hiện việc này, hãy sử dụng phương thức sau:

```lua
ysdk.dispatch_event("EXIT")
```

---



<!-- source: vi/_includes/button-git-defold.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">Kho lưu trữ</span>
</a>
<!-- endsource: vi/_includes/button-git-defold.md -->
