-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Local schema mismatch from server" - when defining multiple rooms/states #131
Comments
Hi @endel, I also got this error, but i am using javascript instead of typescript on the server side. |
Hi @sorrow31812, for plain JavaScript it is a bit complicated, the general suggestion is to always use TypeScript: // javascript
const schema = require("@colyseus/schema");
// create a new context
const context = new schema.Context();
class MyState extends schema.Schema {
}
schema.defineTypes(MyState, {
currentTurn: "string"
}, context); // use the context Make sure you use the specified |
I get it, thanks for your help! 👍 |
Another known appearance of the "schema-mismatch" problem was just found by @drburton when duplicating a field name through inheritance. Just documenting this here, as a fix is coming soon! How to reproduce class Entity extends Schema {
@type("string") id: string;
@type("string") ownerId: string;
@type("number") xPos: number = 0;
@type("number") yPos: number = 0;
@type("number") zPos: number = 0;
}
class Player extends Entity {
@type("string") id: string; // duplicate "id" from Entity - "schema-mismatch" is going to happen!
@type("boolean") connected: boolean;
} EDIT: since |
hello dear friends |
This error is reported often, and one of its causes is when multiple room/state classes are defined in the server with the same schema "context".
Internally, every
@type()
call is going to register the property in a "global" context:To avoid registering every schema in the global context, you can create a different context like this:
Actions needed:
The text was updated successfully, but these errors were encountered: