Confused about matchmaking user ready state

Hi!
I have followed this template/tutorial:

I’m at the point where players can join a game via matchmaking, but I can’t figure out how many people are supposed to be in a match. In my game, there can be between 2 and 8 players in a match.

I think this is how matchmaking works:

  • Players join matchmaker
  • Players are added to the match in matchmakerMatched
    • match is created after threshold(s) are met
  • Players get the matchId
    • Players can join the match via matchId
  • we eventually get to the matchInit, matchJoinAttempt, matchJoin, matchLoop part on the server

At this point, how do the clients know how many players are supposed to be in a match? How can I tell if all of the matched players have joined?
Obviously, if 8 players have joined, the match is full, and every matched player has joined.

On the server, in the match* eg.: matchLoop methods, I have no idea how many people are supposed to be in the match. I haven’t found a way to query it, and it does not get passed in as a parameter as far as I can tell. In the sample, it is irrelevant, because it is only for 2 players.

Do I have to somehow store this information in a database outside of nakama in the matchmakerMatched method?

I am sure, that I have missed something in your docs. :slight_smile:

Sidenote:

Things that have a very specific lifecycle, like matchmaking, or matches, would greatly benefit from visual guides/diagrams. :heart:

  1. Versions: Nakama v3.35.1, Windows, Mac, Linux, .NET SDK v3.21.1
  2. Server Framework Runtime language TS

Edit:

In this sample, the requiredPlayerCount is just a constant 2. The game logic is disconnected from the matchmaking just like in the nakama-project-template.

Hi @tbtbtb,

As you can see in the tic-tac-toe example in the nakama-project-template, the matchJoin callback is invoked after matchJoinAttempt returns true for a specific presence, at this point, the client will be notified of the new presence by listening to the ReceivedMatchPresence callback.

On the server-side MatchJoin hook, you need to keep track of presences in your match state (as in the tic-tac-toe example), so you should update the map or array of presences you’re keeping with the presences received in the MatchJoin function. You should also make sure you’re removing any presences from your state in the MatchLeave hook to make sure your match knows if a player left or disconnected.

In your MatchLoop, you’d check whether the presences you’re keeping in the state reached the target number, and then either start the game, or check if there’s other preconditions (all players have set themselves as ready, for example). If all preconditions are met, you’d start your game logic, typically this would mean having a custom opcode that signals the game start, that the matchLoop broadcasts to the clients, and initiate the actual game loop logic.

Hope this clarifies.