SOLVED. I’ll read the function better, the label was set to null, the one was for player count.
Hi,
I have this rpc function that the player uses to search for a match or to create a new one if there was no match found.
It should only list match with a label :1 .
When a player joins a match and that there are 2 players in the match, the match label switch to 0. The console is showing correctly that the match label has switch to 0.
But when the two players of a match leaves it and relaunch this function to search for a new match or create a new match, it brings them back to the old one that has his label turned to 0 instead of searching for matches that have a label:1.
The label is still to 0 all the time even when they rejoin the match (which they should be able to do in the first place)
let rpcFindMatchPairImpair: nkruntime.RpcFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {
if (!ctx.userId) {
throw Error('No user ID in context');
}
if (!payload) {
throw Error('Expects payload.');
}
let matches: nkruntime.Match[];
try {
matches = nk.matchList(10, true, null, null, 1, null);
} catch (error) {
logger.error('Error listing matches: %v', error);
throw error;
}
let matchIds: string[] = [];
if (matches.length > 0) {
// There are one or more ongoing matches the user could join.
matchIds = matches.map(m => m.matchId);
logger.error('Another user could join a match, we need to send him back a matchid');
} else {
// No available matches found, create a new one.
try {
matchIds.push(nk.matchCreate(moduleNamePairImpairPvP));
logger.error('We have created a Pair Impair PvP match following a user request');
} catch (error) {
logger.error('Error creating match: %v', error);
throw error;
}
}
let res: RpcFindMatchResponse = { matchIds };
return JSON.stringify(res);
}
function rpcPairImpairPvBCreateMatch(context: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string
{
var matchId = nk.matchCreate('pairimpairvsbot');
return JSON.stringify( { "match_id": matchId });
}
Screen when a player has asked the server to create match as he could not find one, the label is set to 1 as it should be:
Screen during the match showing the label to 0 once the two players are here.
Screen before a user tries to find a new match, label still to 0, no more players
Screen after a player tried to search a new match, he joins that match with its label to 0 except he should not have been able to do so.