---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
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: zh/sdk/defold/environment.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/zh/llms.txt

# 环境变量

<!-- 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
  },
  browser: {
    lang: string
  },
  i18n: {
    lang: string;
    tld: string;
  },
  payload: string|nil;
}
```

## environment 对象 {#environment-object}

包含游戏环境变量。

#|
|| **参数** | **类型** | **描述** ||
|| `app` | table | 游戏数据。 ||
|| `browser` | 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。 ||
|#

### browser 结构 {#browser-structure}

#|
|| **参数** | **类型** | **描述** ||
|| `lang` | string | 浏览器的优先语言，格式为 ISO 639-1。 ||
|#

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

#|
|| **参数** | **类型** | **描述** ||
|| `lang` | string | ISO 639-1 格式的 [Yandex Games 界面语言](https://yandex.com/dev/games/doc/zh/concepts/languages-and-domains.md#languages)。例如，`"tr"` 表示游戏当前正在 Yandex Games 土耳其语界面下运行。建议使用此参数确定用户在游戏中使用的语言。 ||
|| `tld` | string | 顶级域名。例如，“com”表示游戏当前在 Yandex Games 的国际域名上运行。如果将游戏部署在自己的域名上，请确保它能够在任何 yandex 域名上正常打开。 ||
|#

---



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