colyseus / colyseus-defold

⚔ Colyseus SDK for Defold Engine
https://docs.colyseus.io/getting-started/defold-client/
MIT License
60 stars 10 forks source link

Serialization problems #12

Closed emarkk closed 5 years ago

emarkk commented 5 years ago

I am using Colyseus with Defold, and I get problems when the state changes. I am using the following Schema for serialization:

import { Schema, type } from '@colyseus/schema';

export class PlayersState extends Schema {

    @type("number")
    connectedPlayers: number = 0;

    addPlayer() {
        this.connectedPlayers++;
    }
    removePlayer() {
        this.connectedPlayers--;
    }

}

The Room code is this:

import { Room, Client } from 'colyseus';

import { PlayersState } from './playersState';

export class PlayersRoom extends Room<PlayersState> {

    onInit (options: any) {
        this.setState(new PlayersState());
    }
    onJoin (client: Client, options: any) {
        this.state.addPlayer();
    }
    onMessage (client: Client, message: any) {
        //
    }
    onLeave (client: Client, consented: boolean) {
        this.state.removePlayer();
    }
    onDispose() {}
}

And when the state changes I get these errors in the console

DEBUG:SCRIPT: /colyseus/serialization/schema/schema.lua:1024: attempt to index local 'root_type' (a nil value)
DEBUG:SCRIPT: /colyseus/serialization/schema.lua:22: attempt to index field 'state' (a nil value)

Is it a bug or a problem in my code?

endel commented 5 years ago

Hi @emarkk, yesterday I've pushed a change on @colyseus/schema, please try updating it to version 0.4.25. Make sure you have the latest version of the defold client as well!

You can remove your local node_modules, package-lock.json, and run npm install again.

Let me know if this fixes your problem. Cheers!

emarkk commented 5 years ago

It works like a charm. Thank you so much.