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

# 环境变量

<!-- source: zh/_includes/script-common.md -->
<!-- source: zh/_includes/script/index-js.md -->

<!-- endsource: zh/_includes/script/index-js.md -->

<!-- source: zh/_includes/script/requirements-js.md -->

<!-- endsource: zh/_includes/script/requirements-js.md -->

<!-- source: zh/_includes/script/image-modal-js.md -->

<!-- endsource: zh/_includes/script/image-modal-js.md -->
<!-- endsource: zh/_includes/script-common.md -->

您可以获取有关游戏运行环境的信息。为此，请使用 `ysdk.environment` 对象。

```lua showLineNumbers
{
    app: {
        id: string
    },
    i18n: {
        lang: string
    },
    payload: string|nil
}
```

## environment 对象 {#environment-object}

包含游戏环境变量。

#|
|| **参数** | **类型** | **描述** ||
|| `app` | `table` | 游戏数据。 ||
|| `i18n` | `table` | 服务国际化。 ||
|| `payload` | `string`\|`nil` | 游戏地址中 `payload` 参数的值。 可选参数。 例如，对于游戏 `https://yandex.ru/games/app/123?payload=test`，可以通过以下方式获取 `test` 的值：`ysdk.environment.payload`。
 ||
|#

### app 结构 {#app-structure}

#|
|| **参数** | **类型** | **描述** ||
|| `id` | `string` | 游戏 ID。 ||
|#


### i18n 结构 {#i18n-structure}

#|
|| **参数** | **类型** | **描述** ||
|| `lang` | `string` | [Yandex Games 界面语言](https://yandex.com/dev/games/doc/zh/concepts/languages-and-domains.md)，格式为 ISO 639-1。 例如，`"tr"` 表示游戏当前在 Yandex Games 的土耳其语界面中运行。 此参数应用于自动检测游戏中的用户语言（[游戏要求项 2.14](https://yandex.com/dev/games/doc/zh/concepts/requirements.md#2-14)）。
 ||
|#

---


<!-- source: zh/_includes/sdk/button-git.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">存储库</span>
</a>
<!-- endsource: zh/_includes/sdk/button-git.md -->
