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.

Moving Items between ArraySchemas issues

See original GitHub issue

I have an issue with moving items between ArraySchemas in my project. Client-side has issues getting all the values of the item and just fills them with undefined.

I modified colyseus-examples to reproduce it and its worse, I get more errors on the client: https://github.com/Zielak/colyseus-examples (in 02-state-handler):

  • addItem - button adds new Item to current player
  • moveItem - moves one item from current player to some other random player

On the first “moveItem” I get this error in browser:

Uncaught TypeError: Cannot read property '_schema' of undefined
    at colyseus.js:1
    at t.e.decode (colyseus.js:1)
    at colyseus.js:1
    at t.e.decode (colyseus.js:1)
    at e.patch (colyseus.js:1)
    at e.patch (colyseus.js:1)
    at e.onMessageCallback (colyseus.js:1)
    at t.value (colyseus.js:1)

Here’s what I do on server-side:

// Pick an item
const item = this.players[id].items[itemIdx];

// Remove that item from myself
this.players[id].items.splice(itemIdx, 1);

// Add it to the other player
targetPlayer.items.push(item);

and the changes on server-side are all there, I explore the state and all the items are in the correct position after “moving”, and with correct values.

I added tests on colyseus/schema with the same use case and the tests pass: https://github.com/Zielak/schema/commit/c2c2eabd2f5e72dd3b92c44ba22ae0a6ecf95f40

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Zielakcommented, Aug 24, 2019

Yes we can!

1reaction
Zielakcommented, Jun 17, 2019

Just an update on what I found while debugging Colyseus. Here’s the case:

  • I’m listening for onStateChange room event
  • I’m moving one item, a playing card, to different ArrayScheme
  • It’s got properties like: x, y, angle, idx, suit and rank. (‘idx’ is its true position in hand)

In the browser, decoding stops after x, y, angle and idx. Thats why I have a bunch of undefined values for this card.

On server side, at the moment of encoding this one card, I can see that Colyseus choses to encode only properties saved in $changes.changes, which contains only x, y, angle and idx.

// Schema.ts:509
const keys = (encodeAll || client)
    ? value.$changes.allChanges
    : value.$changes.changes;

Which kinda makes sense, because while moving this card to another container:

  • it’s position changes - x, y
  • it’s angle changes - cards are rotated differently when in hand or on the pile of cards)
  • it’s idx changes - in my case, I choose 8th card in my hand to be moved to empty container, so its new idx becomes 0

The name, suit and rank don’t actually change, it’s still 8 of hearts.

I don’t feel confident enough with Colyseus codebase to try my own fix, but hopefully you’ll find some use in my investigation. 🤗

Read more comments on GitHub >

github_iconTop Results From Across the Web

ArraySchema is not resolving #140 - GitHub
I will give it a try. But the nested arraySchema is there to describe the list it self, and the schema prop is...
Read more >
Joi, validate different array schemas based on array length
The issue is doesn't seem to be a simple way to validate an array of objects based on if the array length is...
Read more >
Web of Things (WoT) Thing Description - W3C
This document describes a formal model and a common representation for a Web of Things (WoT) Thing Description.
Read more >
Battle Array Schemas (Zhentu) in Middle Period China - Brill
Few scholars study battle array schemas as an historical element of warfare, however, because they understand them as superstitious or mystical, rather.
Read more >
Specify an Array of Strings as Body Parameters in Swagger
The problem is, of course, when things fall apart in production - debugging the implementation of a 3rd party library you have no...
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