Moving Items between ArraySchemas issues
See original GitHub issueI 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:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes we can!
Just an update on what I found while debugging Colyseus. Here’s the case:
onStateChange
room eventIn 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.Which kinda makes sense, because while moving this card to another container:
idx
becomes0
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. 🤗