CREATE YOUR WORLD
Multiplay

Multiplay Room State

8min
multiplay room provides a state property for managing connected player or object location state's data definition be managed from the schema file, which is below the multiplay package the onstatechange event is first called when the client successfully establishes a connection to the room, and is afterwards called whenever there are changes to the state data server api api description state schema name you can access the schema name field defined in the schema file with state you can modify the field value at a request from a client or internal server logic the changed state is then automatically propagated to the clients using the onstatechange event 📘 please refer to the following guide \[ zepeto multiplay(server) api https //developer zepeto me/docs/multiplay server/classes/zepeto multiplay sandbox#state ] import { location } from 'zepeto multiplay schema'; export default class extends sandbox { const location location = this state playerlocation; // handling state } api description room onstatechange(state, isfirst) you can register a state change callback when you join the room you can receive the state of the entire room for the first time, and only the changed state will be received afterwards client api import { zepetoscriptbehaviour } from 'zepeto script'; import { location } from 'zepeto multiplay schema'; export default class sampleclient extends zepetoscriptbehaviour { start() { this multiplay roomjoined += (room room) => { room onstatechange += this onstatechange; }; } private onstatechange(state state, isfirst boolean) { const location location = state playerlocation; // handling player location using updated state } } define schema file schema is a data structure for defining the current state in the room rooms are primarily used to manage player information, player or object locations, etc to edit a schema, you can select project view → multiplaypackage asset → schema json, and then modify the data type to use for the world in the inspector window you can modify the data type to use for the world in the inspector window step 1 defining schema types scheme types is the data structure used in the world in the inspector → schema types, press the \[+] button and add data step 2 add room state the room state is the property that shows the current status of the world room, and is expressed in the schema structure as defined above among the schema types, select the typeroom state that will be used as the current status of the world and set it as the schema name schemas json example { "state" {"players" {"map" "player"}}, "player" {"sessionid" "string","zepetouserid" "string","transform" "transform","state" "number","substate" "number"}, "transform" {"position" "vector3","rotation" "vector3"}, "vector3" {"x" "number","y" "number","z" "number"} }