Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. trenrod
  3. Posts
  • Profile
  • More
    • Continue chat with trenrod
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Posts made by trenrod

Nestesd states not updated on client (no listen event triggered)

Hi,

I dont understand how nested states needs to be changed on server side to trigger the listen event on client side.
I would like to use following classes as custom states.

Room

...
onInit() {
   this.state.setState(new GameState());
}

GameState

export class GameState {
  players: EntityMap<PlayerState> = {};
...

PlayerState

export class PlayerState {
  tilePosX: number = 0;
  tilePosY: number = 0;
  isNpc: boolean = false;
  moveDirState: MoveDirState = MoveDirState.NONE();

MoveDirState

export class MoveDirState {
  moveDir: MOVE_DIR = MOVE_DIR.NONE;
  time: number = 0;

Problem is that any change to PlayerState.moveDirState does not trigger listen events on client. Even that moveDirState is initially send to client

// Initial update with moveDirState as attribute
{ operation: "add",  attribute: "moveDirState" , value: { moveDir: 4, time: 0} ... }

any update on serverside (this is a player instance)

// Not working tries
// 1 Not working helper to set values inside the class
// this.moveDirState.set(moveDir, time);
// 2 Not working set attributes from player class
this.moveDirState.moveDir = moveDir;
this.moveDirState.time = time;
// 3 Not working creating new instance
this.moveDirState = new MoveDirState(moveDir, time);

// Just to check if update working, this is working
this.tilePosX -= 1;

Listener on client side looks like this.


this.room.listen("players/:id/:attribute", (change: DataChange) => {
   console.log("Update state for " + change.path.id, change);
   ...
});

Thank you very much

posted in Questions & Help • 5 Jul 2018, 08:26

© 2023 Endel Dreyer