> 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/you-xi/game.setleaderboardscore.md).

# Game.setLeaderboardScore

> 函数式 API `submitGameCenterLeaderBoardScore`也能用它实现相同功能。

### 功能说明

将用户的游戏分数提交到 Toss 游戏中心排行榜。 `score`需要将浮点数形式的数字作为字符串传递。例如 `"123.45"` 或 `"9999"`。

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

### 类型

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

**参数**

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

**响应**

```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）形式的字符串传递 |

### 示例代码

```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/you-xi/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.
