Studio GuideWorld SDK Guide
Log In

Temporarily Restricting Room Access in Multiplay

You can use the lock, unlock function to restrict or allow room access at your desired timing.

Lock

The lock function is a function restricts room access.

await this.lock();

Unlock

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.

await this.unlock();

Example

The following is an example code that uses the lock and unlock functions.

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

export default class extends Sandbox {

    onCreate(options: SandboxOptions) {

    }

    async onJoin(client: SandboxPlayer) {
        try {
            if (this.clients.length > 8) {
                await this.lock();
            }
        } catch(e) {
            console.error(e);
        }
    }

    async onLeave(client: SandboxPlayer, consented?: boolean){
        try {
            if (this.clients.length <= 8) {
                await this.unlock();
            }
        } catch(e) {
            console.error(e);
        }
    }
}