About Saving Room Data

Hi all,
In some cases, the room needs to be destroyed but the state information of the room needs to be recorded in the database so that the state can be restored next time.What do I need to do to implement this requirement? Do I serialize and deserialize directly?

There are many nested data in this root-state. It will be very cumbersome to assemble them when they are stored and used separately. Is there any way to save only root-state?

@endel Can you give me some advice?thank you.

Hi @BlueBang, you should be able to call .toJSON() on your root Schema instance. Does that help?

@endel Thank you for your reply.But this method is called to return an object. How can I put the object into the database?use JSON.stringify?


//serverSide
onCreate(options) {
    //check if need restore
    if(true){
     let roomstate=getRoomStateFromDB();
     this.state=JSON.Parse(roomstate);// Is it used like this?
    }

}

async onDispose() {
    let roomtState=JSON.stringify(this.state.toJSON());
    storeDataBase(roomtState);// Is it used like this?
}



@bluebang seems to. I have the same question, so I think now we must do something like that, but it could be complicated, if the game state will be too large

Maybe use assign to set the data onCreate?