You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using colyseus.js with a javascript front end. Is there any way to update a Schema on the client side and have those updates propagate to listeners (onChange, onAdd, etc.). I know traditionally updates should come from the server, not client, but I'll explain why below.
For example, is there a way to have this work?
let mySchema = new MySchema(); // extends Schema
mySchema.onChange = changes => {
// listen client-side for a change, as usual
console.log(changes);
};
// try to trigger change client-side
// currently does nothing
myScema.foo = 3;
This is somewhat counterintuitive, and while I'm guess it's not a bug per se, I'm hoping there's a way to work around it.
Rationale: My game uses Colyseus for networking, and I've separated my game logic out so that the server can it and the client responds to state update. That works great. However, I'd like to build a client-only single-player version of the game, which doesn't require a server to run. This in theory should be fine. The game logic doesn't depend on anything in node.js, so the client should be able to run it. I've got messages to work just fine, but the problem is that when my game logic updates the state, the client's listeners don't trigger.
I've tried a naive approach, creating a readState (for client updates) and writeState (for game logic mutations, which would normally run on the server). Then I try:
let bytes = this.writeState.encode();
console.log(bytes);
this.readState.decode(bytes);
But this doesn't seem to be recursive, and I'm guessing I've got it wrong. Is there a better workaround. Thanks for any help!
The text was updated successfully, but these errors were encountered:
The approach to simulate server -> client mutations may work. I'm not sure what you mean by "doesn't seem to be recursive". Maybe you've missed some onAdd callback which is necessary to attach more callbacks to child structures. Happy to help on this approach if you can share any code!
I'm using colyseus.js with a javascript front end. Is there any way to update a Schema on the client side and have those updates propagate to listeners (
onChange
,onAdd
, etc.). I know traditionally updates should come from the server, not client, but I'll explain why below.For example, is there a way to have this work?
This is somewhat counterintuitive, and while I'm guess it's not a bug per se, I'm hoping there's a way to work around it.
Rationale: My game uses Colyseus for networking, and I've separated my game logic out so that the server can it and the client responds to state update. That works great. However, I'd like to build a client-only single-player version of the game, which doesn't require a server to run. This in theory should be fine. The game logic doesn't depend on anything in node.js, so the client should be able to run it. I've got messages to work just fine, but the problem is that when my game logic updates the state, the client's listeners don't trigger.
I've tried a naive approach, creating a
readState
(for client updates) andwriteState
(for game logic mutations, which would normally run on the server). Then I try:But this doesn't seem to be recursive, and I'm guessing I've got it wrong. Is there a better workaround. Thanks for any help!
The text was updated successfully, but these errors were encountered: