GitHub Documentation

Uncaught Error: ChangeTree: missing index for field "undefined"



  • Hello everyone,

    I'm currently building a web game (based on colyseus and VueJS).

    I had no problem at all during the whole development, but today I just saw this error pop in the console at a specific moment.
    error-colyseus.png
    It does not block the code and execution.
    It is due to this line of code, server-side, in a listener for client request

    this.state.players.get(client.sessionId).jokers.get(packet.datas).available = false;
    

    I have tried to write it that way but the error is still here

    let player = this.state.players.get(client.sessionId);
    let joker = player.jokers.get(packet.datas);
    joker.available = false;
    

    the property jokers is a mapSchema binded with jokers "slug" so it's easy to find them.

    Why is it causing an error and do you have a tip to avoid it ?

    Thanks !
    Maël


  • administrator

    Hi Maël, welcome! 👋

    Are you using @filter() or @filterChildren()?

    Can you please share your source-code with us, so we can have a bigger picture of the operations on MapSchema? I'm curious to see what's going on as I've never seen this error before!

    Feel free to ping me on Discord (endel#2163) or email (endel[at]lucidsight.com)

    Cheers!



  • Hi @endel ! Thanks

    thank for answering, I'm not using @filter() or @filterChildren().

    Here is the code of the MapSchema :

    export class Joker extends Schema {
        @type("string")
        type: string;
    
        @type("string")
        slug: string;
    
        @type("string")
        name: string;
    
        @type("boolean")
        available: boolean = true;
    
        @type("boolean")
        isUsed: boolean = false;
    }
    

    and it's inplementation in the Schema for the Player

    @type({ map: Joker })
    jokers: MapSchema<Joker>;
    

    I initialize it here (maybe here is the bad code haha) :

    let jokers = new MapSchema<Joker>();
        this.jokers.forEach((jk) => {
            let joker = new Joker({
            type: jk.type,
            slug: jk.slug,
            name: jk.name,
            available: true,
            isUsed: false
        });
        jokers.set(jk.slug, joker);
    })
    

    the jokers array

    jokers = [
            { type: 'bonus', slug: "cdp", name: "Coup d'pouce" },
            { type: 'attaque', slug: "pjn", name: "Petit jaune" },
        ];
    

    And the error throws when I do this :
    this.state.players.get(client.sessionId).jokers.get(packet.datas).available = false;

    Just to know, I use this.state.players.get(client.sessionId).jokers.get(packet.datas).available in a if right before and it doesn't throw error.
    Plus, the error is throwing on client-side in colyseus.js and nothing shows up on server-side.

    Hope it will help !

    Cheers!


 

© 2021 Lucid Sight, Inc