# Make a match with 1 player only

**URL:** <https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630>\
**Category:** Game Design\
**Tags:** sdk-unity, matches\
**Created:** [May 15, 2022, 6:45pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630 "2022-05-15T18:45:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 15, 2022, 6:45pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/1 "2022-05-15T18:45:56Z")

</div>

The game I’m making has 1 to 100 players at the same time.

They are players who do not communicate with each other but each sees the moves of the other (presence and position).

I am working on the matchmaking functions. Unfortunately the matchmaker works with at least 2 participants present but I want to foresee the possibility of playing alone.

What advice do you give me to manage this situation? Keep trying to join in matchmaking? if so I have to provide a shorter timeout to detect new players

thanks for the support

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 16, 2022, 4:46pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/2 "2022-05-16T16:46:58Z")

</div>

@solidsnakeit are you imagining that players would be able to join a match that has already started? Or does the number of players not increase once the match has started?

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 16, 2022, 5:08pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/3 "2022-05-16T17:08:01Z")

</div>

Hi @lugehorsam ,

the number of players can increase during the game but it can also decrease until there is only 1 player.

To give you an example, imagine a whatsapp group: we are all in the group but “online” there may be 1 or more people or no one.

Imagine a game where the player has to collect gems.  
In the game level there can be only one player who collects as many gems as possible and other players can be added.  
The game level remains active for several days: gems are generated every 3 hours. When all 100 gems are collected, the game ends.

Let me know if I can give further explanations.

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 16, 2022, 6:20pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/4 "2022-05-16T18:20:57Z")

</div>

Okay thanks @solidsnakeit. What I would consider is the following:

(1) When a player wants to join a match, use the Match Listing API to find matches of the type he desires.

(2) If there are no matches of his preferred type, create a match and give it a match label that is similar to that which he chose to search with.

(3) Other players can now join his match as well.

Some documentation resources:

> **[Nakama:
    
  
    
    
  
  
  Match Listing |

Heroic Labs Documentation](https://heroiclabs.com/docs/nakama/concepts/multiplayer/match-listing/)**
>
> Documentation for Nakama Open Source, Nakama Enterprise and Heroic Cloud.

> **[Nakama:
    
  
    
    
  
  
  Authoritative Multiplayer |

Heroic Labs...](https://heroiclabs.com/docs/nakama/concepts/multiplayer/authoritative/#match-label)**
>
> Documentation for Nakama Open Source, Nakama Enterprise and Heroic Cloud.

Note you aren’t necessarily using the matchmaker here. That is intended for finding users prior to a match starts. It is possible that you would like to use that as well depending on your particular use case.

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 16, 2022, 7:09pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/5 "2022-05-16T19:09:06Z")

</div>

Thank you @lugehorsam , is just what I needed.  
I understand that I have to use a server function which creates the match if it doesn’t exist.  
(I was focused on the client side)

🙂

---

<div class="post-metadata">

**Author:** ![bodin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bodin/32/1260_2.png) [@bodin](https://forum.heroiclabs.com/u/bodin)\
**Post date:** [May 17, 2022, 7:30am UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/6 "2022-05-17T07:30:57Z")

</div>

I think you may use socket.CreateMatchAsync(MatchName)  
It’s overloaded version of CreateMatchAsync() but you can assign the Match name.

if there’s no match at the moment, It will create a new match and let that player join that match.  
(so basically, it makes a match with 1 player, as you intend to do)

---

<div class="post-metadata">

**Author:** ![formatCvt](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/formatcvt/32/1127_2.png) [@formatCvt](https://forum.heroiclabs.com/u/formatCvt)\
**Post date:** [May 17, 2022, 7:49am UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/7 "2022-05-17T07:49:14Z")

</div>

but if they connected simultaneously we have two matches with one player instead of one with two as result

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 18, 2022, 3:38pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/8 "2022-05-18T15:38:57Z")

</div>

Hi @lugehorsam ,

I followed these instruction with success: Now I’m able to create a match…

BUT

I’munable to find the match with the right label because I’m unable to set it.  
Sure I forgot something but what?

Here my code;

```auto
function rpcLSfindOrCreateMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama): string
{

    let limit = 10;
    let isAuthoritative = true;
    let label = 'Piq400_Match';
    let minSize = 0;
    let maxSize = 100;
    //let matches: nkruntime.Match[] = [];

    var matches = nk.matchList(limit, isAuthoritative, label, minSize, maxSize, "");

    // If matches exist, sort by match size and return the largest.
    if (matches.length > 0) {
        matches.sort((a, b) => a.size >= b.size ? 1 : -1);
        return matches[0].matchId;
    }

    // If no matches exist, create a new one using the "lobby" module and return it's ID.

    var matchId = nk.matchCreate("lobby", {});

    return JSON.stringify({ matchId });
}

```

In summary: where can I set the “label” during match create (I didn’t find the right documentation).

thank you

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [May 18, 2022, 4:09pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/9 "2022-05-18T16:09:30Z")

</div>

Hey @solidsnakeit take a look at the match init function:

> **[Nakama:
    
  
    
    
  
  
  Match Handler API |

Heroic Labs Documentation](https://heroiclabs.com/docs/nakama/server-framework/function-reference/typescript/match-handler/#MatchInit)**
>
> Documentation for Nakama Open Source, Nakama Enterprise and Heroic Cloud.

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 20, 2022, 1:16pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/10 "2022-05-20T13:16:07Z")

</div>

Thank you @lugehorsam .

Things are many and it takes me a while to understand where they are.  
Many thanks, really.

Now I thought I understood but I can’t access the Label property of the match.

The error is as follows:

> error TS2339: Property ‘Label’ does not exist on type ‘Match’.

This is my code:

```auto
        let vIndex = -1;
        let label = "";
        for (let vI = 0; vI < matches.length; vI++)
        {
            if (matches[vI].Label == label)
            {
                vIndex = vI;
                break;
            }
        }

```

I also looked at the “struct” in this file: [nakama-common](https://github.com/heroiclabs/nakama-common/blob/ae25b6937ac0966d5a02a5361f8629e70106b9fb/api/api.pb.go#L5131)

What am I doing wrong?

thank you

---

<div class="post-metadata">

**Author:** ![flavio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/flavio/32/2161_2.png) [@flavio](https://forum.heroiclabs.com/u/flavio)\
**Post date:** [May 20, 2022, 2:02pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/11 "2022-05-20T14:02:37Z")

</div>

Hello @solidsnakeit

I think the definition of what your are looking for should be [here](https://github.com/heroiclabs/nakama-common/blob/master/index.d.ts#L2327). As you can see the `label` (lowercase) isn’t there yet and we will fix that however, the javascript runtime adds the label value anyway [here](https://github.com/heroiclabs/nakama/blob/master/server/runtime_javascript_nakama.go#L3438). Could you try with `label` instead of `Label` ?

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 21, 2022, 2:42pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/12 "2022-05-21T14:42:08Z")

</div>

Hi @flavio ,

no, unfortunately it doesn’t work. This is the error I get:

```auto
rpcLSfindOrCreateMatch.ts:21:29 - error TS2339: Property 'Label' does not exist on type 'Match'.

21 if (matches[vI].Label == label)
                               ~~~~~

```

Is it possible that I’m wrong something like, for example, I don’t include definitions or anything else?

In other hand

matches[vI].matchID is recognized and works well

---

<div class="post-metadata">

**Author:** ![solidsnakeit](https://avatars.discourse-cdn.com/v4/letter/s/e19b73/32.png) [@solidsnakeit](https://forum.heroiclabs.com/u/solidsnakeit)\
**Post date:** [May 23, 2022, 12:52pm UTC](https://forum.heroiclabs.com/t/make-a-match-with-1-player-only/2630/13 "2022-05-23T12:52:41Z")

</div>

I close this ticket and open a new one regarding RPC functions and the properties.

Here the link: [Accessing match properties in RPC functions](https://forum.heroiclabs.com/t/accessing-match-properties-in-rpc-functions/2657)
