---
title: 在私人房间运行时的设置
slug: world-sdk-guide-ch/qhuK3-lUPCEpIrLj6RW2K
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

您可以在运行时更改多人房间属性。

:::hint{type="danger"}
- 请创建服务器代码 index.ts Sandbox。
:::



## 函数定义

| &#x20;                                    |                                         |
| ----------------------------------------- | --------------------------------------- |
| SetPrivate(isPrivate : boolean) : Promise | - True : 设置为私人房间<br />- False : 设置为公共房间 |

:::hint{type="info"}
**📘&#x20;**&#x8BF7;参考以下指南。 \[[ZEPETO.Multiplay(服务器) API](https://developer.zepeto.me/docs/multiplay-server/classes/ZEPETO_Multiplay.Sandbox#setprivate)]
:::

## 使用示例

```typescript
import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';

export default class extends Sandbox {
    
    onCreate(options: SandboxOptions) {
        this.onMessage("SetPrivate", (client: SandboxPlayer, value: boolean) => {
            console.log(`尝试设置私密 : ${value}`);
            this.SetPrivateRoom(client, value);
        });
    }
    
    async SetPrivateRoom(client: SandboxPlayer, value: boolean) {
        await this.setPrivate(value);
        client.send("Log", `房间设置为私密 : ${this.private}`);
    }
}
```

:::hint{type="success"}
**👍 锁定和私密功能之间的区别**

锁定的多人房间在 ZEPETO 房间列表中不可见，且无法通过邀请进入。

- 私密的多人房间在 ZEPETO 房间列表中不显示，但可以接受邀请。
:::

