Make a match with 1 player only

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

@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?

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.

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:

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.

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)

:slight_smile:

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)

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

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;

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

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

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:

        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

What am I doing wrong?

thank you

Hello @solidsnakeit

I think the definition of what your are looking for should be here. 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. Could you try with label instead of Label ?

Hi @flavio ,

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

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

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

Here the link: Accessing match properties in RPC functions