CREATE YOUR WORLD
Multiplay
Temporarily Restricting Room Access in Multiplay
4min
You can use the lock, unlock function to restrict or allow room access at your desired timing.
📘 Please refer to the following guide. [ZEPETO.Multiplay(Server) API]
The lock function is a function restricts room access.
TypeScript
1await this.lock();
The unlock function is a function that allows room access. But, if the number of people who are currently connected is the same as the maximum number of people allowed in the room, the room cannot be unlocked.
TypeScript
1await this.unlock();
The following is an example code that uses the lock and unlock functions.
TypeScript
1import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';
2
3export default class extends Sandbox {
4
5 onCreate(options: SandboxOptions) {
6
7 }
8
9 async onJoin(client: SandboxPlayer) {
10 try {
11 if (this.clients.length > 8) {
12 await this.lock();
13 }
14 } catch(e) {
15 console.error(e);
16 }
17 }
18
19 async onLeave(client: SandboxPlayer, consented?: boolean){
20 try {
21 if (this.clients.length <= 8) {
22 await this.unlock();
23 }
24 } catch(e) {
25 console.error(e);
26 }
27 }
28}
Updated 10 Oct 2024

Did this page help you?