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. leal32b
leal32b

leal32b

@leal32b

Chat Follow Unfollow
0
Reputation
2
Posts
1.1k
Profile views
0
Followers
1
Following
Joined 28 Oct 2020, 20:22 Last Online 30 Oct 2020, 13:55

  • 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 • 29 Oct 2020, 22:50
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 • 28 Oct 2020, 20:43

© 2023 Endel Dreyer