> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/game/game.setleaderboardscore.md).

# Game.setLeaderboardScore

> 函数式 API `submitGameCenterLeaderBoardScore`也可以通过它使用相同的功能。

### 功能说明

在游戏应用中，将用户的游戏分数提交到 Toss 游戏中心排行榜。 `分数`应以字符串形式传递浮点数。例如 `"123.45"` 或 `"9999"`。

Toss App Android/iOS `5.221.0` 可在上述环境中使用。在未能接收到桥接响应的环境中， `undefined`可能会返回。

### 类型

```ts
Game.setLeaderboardScore(params: { score: string }): Promise<SubmitGameCenterLeaderBoardScoreResponse | undefined>;
```

**Params**

```ts
{
  score: string;
}
```

**Response**

```ts
type SubmitGameCenterLeaderBoardScoreResponse = {
  statusCode:
    | "SUCCESS"
    | "LEADERBOARD_NOT_FOUND"
    | "PROFILE_NOT_FOUND"
    | "UNPARSABLE_SCORE";
};
```

响应 `statusCode` 值：

| statusCode              | 说明                          |
| ----------------------- | --------------------------- |
| `SUCCESS`               | 分数提交成功了                     |
| `LEADERBOARD_NOT_FOUND` | 找不到排行榜                      |
| `PROFILE_NOT_FOUND`     | 用户没有资料                      |
| `UNPARSABLE_SCORE`      | 无法解析分数。应以浮点数（float）形式的字符串传递 |

### 错误

如果在非游戏应用的迷你应用中调用，Promise 会被 reject。此时 `error.message`是 `“排行榜 API 只能在游戏应用中使用。”`。

### 示例代码

```js
import { Game } from "@apps-in-toss/web-framework";

const button = document.querySelector("#submit-score");

button.addEventListener("click", async () => {
  try {
    const result = await Game.setLeaderboardScore({ score: "123.45" });

    if (result?.statusCode === "SUCCESS") {
      console.log("分数提交成功！");
    } else {
      console.error("分数提交失败：", result?.statusCode);
    }
  } catch (error) {
    console.error(error);
  }
});
```


---

# 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://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/game/game.setleaderboardscore.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.
