Update changes in a dynamically created schema (Solved)

Hello! I'm currently working on a game and I'm facing an issue. The game is quite simple at the moment because I'm currently working on the architecture.

Here's the logic : an user can click on a button to join a team (Green or Red). I already created a Team Schema which contain an ArraySchema of PlayerTeam.

0_1664488742695_Screenshot 2022-09-29 144441.png

0_1664488772292_Screenshot 2022-09-29 144540.png

When the user click on the button. It will create a new PlayerTeam and will be push to the according Team.

0_1664488814349_Screenshot 2022-09-29 144601.png

0_1664489018640_Screenshot 2022-09-29 150320.png

Since the PlayerTeam schema is dynamicly created and not created initially, I am not able to see if there have been any changes on it. In other words, I'm not able to that :

0_1664488725987_Screenshot 2022-09-29 145834.png

Is there a way to see if there have been any changes on the PlayerTeam schema ? Am I missing something?

Thanks! :)

So I managed to find my solution. Maybe I was a bit confused but I simply had to do another onAdd() inside it. Hope it will help someone.

this.room.state.teams.onAdd = (team, sessionId) => {
team.onChange = (changes) => {
changes.forEach((change) => {});
};

team.playerTeams.onAdd = (playerTeam, sessionId) => {
playerTeam.onChange = (changes) => {};
};
};

Glad you solved it yourself.