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