Hi there, I have a technical question about the query syntax as described in the documentation
I’m currently making an authoritative multiplayer game with multiple game modes.
The players have the option to play a specific game mode, or queue for a random mode.
Now in the documentation it states that I can provide an array of values so the matchList function can return multiple matches with different label values,
Queries also inspect individual elements inside an array for a match. For example, an indexed value:
{"field": [5, 10, 15]}
will be returned as a match for any query including a termfield:5
,field:10
, orfield:15
.
When I ask for a match I check if there are any matches and else I’ll create one with the correct game-mode on the label.
let request = parse(payload);
let matches = getMatches(request)
let matchIds: string[] = [];
if (matches.length > 0) {
// There are one or more ongoing matches the user could join.
matchIds = matches.map(m => m.matchId);
} else {
// No available matches found, create a new one.
matchIds.push(createMatch(request))
}
let res: RpcFindMatchResponse = { matchIds };
return JSON.stringify(res);
But Now I’m encountering a problem that when I notate the query as an array of [0,1] it won’t return any of the existing matches that have game mode 0 or 1. When I write the query as
"+label.open:1 +label.gameMode:0"
or "+label.open:1 +label.gameMode:0"
it does find them so now I’m left wondering if this functionality of the query syntax is broken because I don’t receive any errors because then I would catch them.
function getMatches(request): nkruntime.Match[]{
try {
// const query = request.query;
const query = "+label.open:1 +label.gameMode:[0,1]"
log.debug("the query %v",query);
return nk.matchList(10, true,null, null, 1, query);
} catch (error) {
log.error('Error listing matches: %v', error);
throw error;
}
}
function createMatch(request){
try {
//TODO, create match based on gametype
log.info("creating match")
let gameMode = getGameMode(request.gameModes)
log.info(gameMode.toString())
return nk.matchCreate(gameMode, {fast: request.fast, query: request.query});
} catch (error) {
log.error('Error creating match: %v', error);
throw error;
}
}
I know my match has a int declared in the label because I can see them in the nakama console
I couldn’t find an example on the documentation or forum on how to use an search array.
Does any-one of you know how I could make use of the correct syntax?