Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: States are not triggered in the expected order #702

Open
saltlevent opened this issue Feb 28, 2024 · 4 comments
Open

[Bug]: States are not triggered in the expected order #702

saltlevent opened this issue Feb 28, 2024 · 4 comments
Labels
🧮 @colyseus/schema Problems related to Schema Serializer 🐛 bug
Milestone

Comments

@saltlevent
Copy link

Context

No response

Bug description

I have 2 states these are ArraySchema and number(int64). In server when I update the arrayschema before number, client get the OnAdd event from arrayschema after number change event. This cause a little bit challenge for our project. How can we solve this problem?

server-side:

export class Actor extends Schema {
  @type(["string"])
  boardTiles = new ArraySchema<string>();
  @type("int64")
  actionType: ActionTypes = ActionTypes.None;
}
export class Game extends Schema {
      drawPlayedTile() {   
            //...some codes
           actor.boardTiles.push(tile);
           //...some codes
           this.setActorActionType(ActionTypes.DrawPlayedTile, actor);
       }
}

client-side logs:
->OnActionTypeChange
->OnAdd: boardTile

Reproduction

No response

Steps to reproduce

  1. created state that has arrayschema and number.
  2. first arrayschema updated and then number updated.
  3. In client (Unity), arrayschema has OnAdd triggered after OnNumberChanged triggered.

Environment & Versions

Colyseus version: 0.15.15
Node version : v16.20.1
Typescript version : 4.9.5
Operating System: Linux Ubuntu 18.04.6 LTS

@endel
Copy link
Member

endel commented Feb 28, 2024

Interesting, thank you for reporting @saltlevent, I can confirm this is happening here: https://stackblitz.com/edit/colyseus-schema-issue-report-vxwj94?file=index.ts

I'm currently working on a new version of @colyseus/schema with a big restructuring, so I'll investigate if it's possible to fix this issue there. I'm afraid v2 will continue to behave like it is right now.

There are 2 options you could take right now: use the onStateChange to perform the action you need (it runs after all schema callbacks run), or send another message after mutating the state.

@endel endel added 🧮 @colyseus/schema Problems related to Schema Serializer and removed 👀 triage labels Feb 28, 2024
@saltlevent
Copy link
Author

Thank you for quick reply, I'll try what you said then ill reply.

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 29, 2024
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@endel endel removed the Stale label May 13, 2024
@endel endel reopened this May 13, 2024
@endel endel added this to the 0.16 milestone May 13, 2024
endel added a commit to colyseus/schema that referenced this issue May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧮 @colyseus/schema Problems related to Schema Serializer 🐛 bug
Projects
None yet
Development

No branches or pull requests

2 participants