question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArraySchema<number> issue

See original GitHub issue

I had a schema “A” with ArraySchema<number> “items”. Then I push to array “items” values: 1, 2, 3. On Client side A.onChange(value, key) triggers on every update and I got the following values in items:

A.items: [1]
A.items: [undefined, 2]
A.items: [undefined, 2, 3]

02-state-handler.zip

You can check it on “02-state-handler” example by adding a few line of code:

Add ArraySchema<number> in Player class:

    @type(["number"])
    moves = new ArraySchema<number>();

In state class add method:

    addItem(id, item) {
        this.players[id].moves.push(item);
    }

in StateHandlerRoom class call method on every message:

    onMessage (client, data) {
        console.log("StateHandlerRoom received message from", client.sessionId, ":", data);
        this.state.movePlayer(client.sessionId, data);
        this.state.addItem(client.sessionId, data.x || data.y );
    }

On client-side just add one line in “room.state.players.onChange”:

console.log(player.moves)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
udamircommented, Nov 7, 2019

I have sent you my code to your email.

0reactions
endelcommented, Dec 22, 2019

I’m going to close this as it seems to be fixed on the latest versions. Feel free to re-open if you still have problems after upgrading (rm -R node_modules package-lock.json && npm install)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with using basic array schema in flow
Hi all I'm trying to take in some values when into an array when they are created in an MS form. It takes...
Read more >
Array schema has no maximum number of items defined
This issue ID and article have been deprecated and will be removed. Description. An array schema does not specify the maximum number of...
Read more >
Swagger UI array schema not allowing comma delimit...
Is seems as though because the UI is marking the input of the list of numbers as a number the comma isn't valid....
Read more >
Schema - Colyseus & Arena Cloud Documentation
Primitive types are numbers, strings and boolean. ... import { Schema, ArraySchema, type } from "@colyseus/schema"; ... See this issue for a workaround....
Read more >
Json with Nested Array Schema
If I used the first object in the JSON, there is no issue. Only when I use the complete JSON array do I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found