# Players in pool not getting matched by matchmaker

**URL:** <https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124>\
**Category:** Client Libraries\
**Created:** [October 4, 2022, 2:21pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124 "2022-10-04T14:21:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 4, 2022, 2:21pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/1 "2022-10-04T14:21:27Z")

</div>

As the title says, I am having trouble getting people in a pool matched together. They just show up as separate tickets but the match requirements (query, min/max players) never get fulfilled.

### Frontend code

```auto
const ticket: MatchmakerTicket = await socket.addMatchmaker("*", 2, 2);
console.log(ticket);

socket.onmatchmakermatched = (matched) => {
  console.info("Received MatchmakerMatched message: ", matched);
  console.info("Matched opponents: ", matched.users);
};

```

* * *

### Backend code

```auto
export const matchmakerMatched = (
  _context: nkruntime.Context,
  logger: nkruntime.Logger,
  nk: nkruntime.Nakama,
  matches: nkruntime.MatchmakerResult[]
): string => {
  logger.info("Match is Made");

  matches.forEach(function (match) {
    logger.info("Matched user '%s' named '%s'", match.presence.userId, match.presence.username);

    Object.keys(match.properties).forEach(function (key) {
      logger.info("Matched on '%s' value '%v'", key, match.properties[key]);
    });
  });

  try {
    const matchId = nk.matchCreate("standard", { invited: matches });
    logger.debug(matchId);
    return matchId;
  } catch (error) {
    throw logError(error, logger);
  }
};

```

* * *

### Init

` initializer.registerMatchmakerMatched(matchmakerMatched);`

* * *

### Logs of 3 clients trying to get matched. The ticket gets shown in `console.log()` as per the frontend code

 ![Screenshot 2022-10-04 at 15.39.01](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/5/5139f8a5d2fc3508d296ca506a1cfd7b9cfe4b3b.png)

* * *

Nothing is happening after this.  
`matchmaker.interval_sec` is set to 15 but even after waiting that long it stays quiet.

So on both the frontend (socket) as the backend (hook) the matchmaking doesn’t get triggered. I also tried them separately but without success.

Any clue? Thanks in advance 🙏

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [October 4, 2022, 4:52pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/2 "2022-10-04T16:52:17Z")

</div>

@nick Can you also share the client SDK and server versions? Also make sure you register `socket.onmatchmakermatched` hooks _before_ submitting your tickets.

Side note - screenshots of code or logs are not ideal. Use text where possible so we can copy/paste or alter for responses.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 5, 2022, 7:48am UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/3 "2022-10-05T07:48:40Z")

</div>

Thanks for your response.

Client SDK: **@heroiclabs/nakama-js 2.4.1**  
Server version: **3.9.0+6f4c456b**

And I also tried registering the socket before submitting the ticket, but that’s not changing anything sadly. Also tried an empty query string as I saw in an example in the docs.

And sure, I will paste the code next time 👍

BTW, is there a way to debug the matchmaking pool? To see how many people are there with what kind of query etc.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 5, 2022, 8:41am UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/4 "2022-10-05T08:41:15Z")

</div>

Weird thing is, that even when I try to log `socket.onmatchmakerticket`, it isn’t firing when a ticket is generated.

### Code

```auto
socket.onmatchmakermatched = async (matchmakerMatched) => {
  console.log("matched");
  console.log(matchmakerMatched);
};

socket.onmatchmakerticket = async (matchTicket) => {
  console.log("onmatchmakerticket");
  console.log(matchTicket);
};

console.log(socket);

const query = "*";
const minPlayers = 2;
const maxPlayers = 2;

const matchmakingTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);

console.log(matchmakingTicket);

```

### Console output

 ![Screenshot 2022-10-05 at 10.32.08](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/f/fc5cebc55584644360ae13c6992959a429b8b852.png)

So it seems like it is not registering that a ticket has been created.  
The backend log doesn’t show any error:

```auto
[backend] {"level":"debug","ts":"2022-10-05T08:30:47.746Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"b024ef99-0268-47c8-89fe-3e5e640fbf2e","sid":"01ab35cf-4488-11ed-ad69-006100a0eb06","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T08:30:47.748Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"b024ef99-0268-47c8-89fe-3e5e640fbf2e","sid":"01ab35cf-4488-11ed-ad69-006100a0eb06","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"943e12d1-5769-4667-9029-772f7c7e0071\"}"}

```

Last thing worth mentioning (not sure if matters) is that the `cid` (is that the Client ID?) stays at `1`, even when I am creating a ticket from another client.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 5, 2022, 11:21am UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/5 "2022-10-05T11:21:48Z")

</div>

Playing around with it more, and even if I trigger 3 tickets (`matchmaker.max_tickets`) from the same client, it gets registered with the correct amount of `cid`s, but still nothing gets triggered in the console, and the registered `MatchmakerMatched` isn’t called either.

### Code

```auto
socket.onmatchmakermatched = async (matchmakerMatched) => {
  console.log("matched");
  console.log(matchmakerMatched);
};

socket.onmatchmakerticket = async (matchTicket) => {
  console.log("onmatchmakerticket");
  console.log(matchTicket);
};

const query = "*";
const minPlayers = 2;
const maxPlayers = 2;

const ticket1: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);
const ticket2: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);
const ticket3: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);

```

### Logs

```auto
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.658Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.663Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"d69cabe6-d7fb-4f29-9cb8-40f29f607936\"}"}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.668Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"2","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.672Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"2\" matchmaker_ticket:{ticket:\"1c462799-3e1d-49ad-b6bb-10fd4342f666\"}"}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.676Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"3","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.679Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"3\" matchmaker_ticket:{ticket:\"bad368be-0325-401f-9591-b0a8acee2972\"}"}

```

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [October 5, 2022, 2:56pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/6 "2022-10-05T14:56:28Z")

</div>

@nick Start by updating to Nakama 3.13.1 and try again, we can debug further once you’re on the most recent version with all known bugfixes applied. 🕶

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 5, 2022, 3:11pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/7 "2022-10-05T15:11:49Z")

</div>

@zyro But 2.4.1 is the latest release?

> **[Releases · heroiclabs/nakama-js](https://github.com/heroiclabs/nakama-js/releases)**
>
> JavaScript client for Nakama server written in TypeScript. - heroiclabs/nakama-js

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [October 5, 2022, 4:05pm UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/8 "2022-10-05T16:05:47Z")

</div>

Nakama is the server, nakama-js is your client library. Your server is 3.9.0 per your own post a bit above. Update that to 3.13.1.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/nick/32/1353_2.png) [@nick](https://forum.heroiclabs.com/u/nick)\
**Post date:** [October 6, 2022, 9:21am UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/9 "2022-10-06T09:21:04Z")

</div>

@zyro well I guess that worked 😅 Thanks!

Unrelated question, is there a Nakama go-to way for a situation where users that get a matchmaking ticket are joining either a game with default settings or a game with predefined settings created by one of the users?

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [October 6, 2022, 10:49am UTC](https://forum.heroiclabs.com/t/players-in-pool-not-getting-matched-by-matchmaker/3124/10 "2022-10-06T10:49:58Z")

</div>

That sounds like a new topic, please start a new thread and give as much detail as you can about your use case. 👍
