Sending Objects to Construct 3

I am having a issue. I am trying to create an array of objects and trying to get that array of objects and break it down in construct 3. I dont know how to read the objects in construct 3 can anyone help?

onJoin(client, options){
this.playerCount ++;

    let newPlayer = {
        id: client.sessionId,
        x: 100,
        y: 100
    }

    this.players.push(newPlayer);

    this.players.forEach(player=>{console.log(player)});
    this.send(client,{
        type: "players",
        list: this.players
    })
}

How will i be able to read this list of objects in construct 3?

Hi @NycGio,

It's recommended to keep your map of users in the state (using plain Object instead of Array's), and listen for changes in the state.

Example:

this.state.players = {};
this.state.players[client.sessionId] = { x: 100, y: 100 };

You'd then need to listen for additions and changes on players, using the Listen condition:

  • Listen: operation = any, path = "players/:id" (listens for add/remove operations)
  • Listen: operation = replace, path = "players/:id/:attribute" (listen for changes on attributes)

There's a discussion on the repository about storing and retrieving entities/players by an id string. I'm not sure yet how to keep that reference on Construct3. Maybe you have some idea?

@endel thank you so much