Navigation

    Colyseus
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. leal32b
    leal32b

    leal32b

    @leal32b

    Chat Follow Unfollow
    0
    Reputation
    2
    Posts
    1227
    Profile views
    0
    Followers
    1
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with leal32b
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    leal32b Follow

    Posts made by leal32b

    RE: How to get arrays on javascript client?

    @endel said in How to get arrays on javascript client?:

    console.log(Array.from(proxy))

    Thanks a lot, endel!! Worked perfectly!
    Colyseus rocks! xD

    posted in Questions & Help •
    How to get arrays on javascript client?

    Hey guys!

    I just started working with Colysus and liked it a lot!
    But there is something I can't understand yet...

    This is my Player class:

    import { Schema, type } from '@colyseus/schema';
    
    class PlayerState extends Schema {
      @type('number') level: number = 0;
      @type('number') timer: number = 300;
      @type('number') points: number = 0;
      @type('number') errors: number = 0;
      @type('boolean') error: boolean = false;
    }
    
    class GameState extends Schema {
      @type(['number'])
      game: number[] = [];
    }
    
    export class Player extends Schema {
      @type('string')
      sessionId: string;
    
      @type('string')
      name: string;
    
      @type(PlayerState)
      state: PlayerState = new PlayerState();
    
      @type(GameState)
      gameState: GameState = new GameState();
    }
    

    When I listen to changes on PlayerState, for example, it's ok I get the information:

    player.state.onChange = (changes) => {
        changes.forEach((c) => {
          this.players[this.getPlayerIndex(key)].state[c.field] = c.value;
        });
    };
    
    [{op: 128, field: "level", dynamicIndex: undefined, value: 0, previousValue: undefined},
    {op: 128, field: "timer", dynamicIndex: undefined, value: 300, previousValue: undefined},
    {op: 128, field: "points", dynamicIndex: undefined, value: 0, previousValue: undefined},
    {op: 128, field: "errors", dynamicIndex: undefined, value: 0, previousValue: undefined},
    {op: 128, field: "error", dynamicIndex: undefined, value: false, previousValue: undefined}]
    

    But when get the information from GameState ('game' wich is an array) I get this:

    [{op: 128, field: "game", dynamicIndex: undefined, value: Proxy, previousValue: undefined}]
    
    Proxy {$changes: ChangeTree, $items: Map(16), $indexes: Map(16), $refId: 0, $proxy: true}
    

    How can I deal with this 'Proxy'?
    I've tried a lot of stuff and nothing works...
    I would like to understand how to read it, get the original array from this and get the changes.

    Thanks in advance!

    posted in Questions & Help •