Sign In Register

How can we help you today?

Start a new topic
Answered

customQuery in MatchmakingRequest

Please give an example of customQuery in MatchmakingRequest for Unity and json

https://docs.gamesparks.com/api-documentation/request-api/multiplayer/matchmakingrequest.html




Best Answer

Hi Vsevolod,


Apologies for the delayed response, I'm not sure why this went unanswered for this long. To answer your question a custom query can be used to further refine the match making process. It allows you to query the participant data of a pending match. Here's a basic example for you using countries. You can try this yourself by opening two test harness windows and logging in as two different players.


  

//player one sends a MatchMakingRequest with the participantData set to {"country":"ireland"}
{
 "@class": ".MatchmakingRequest",
 "participantData": {"country":"ireland"},
 "matchShortCode": "testMatch",
 "skill": 2
} 

//player two then sends a MatchMakingRequest with the custom query set up to look for a match with the country set to Ireland.

{
 "@class": ".MatchmakingRequest",
 "customQuery": {"players.participantData.country":"ireland"},
 "matchData": {},
 "matchShortCode": "testMatch",
 "skill": 2
}

 

In this instance the players will be matched. If you were to repeat the process with player 2 set to query for the "UK" both players would get a MatchNotFoundMessage. I hope that clears that up for you. If you have any further questions just let us know.


Thanks,

Liam




Answer

Hi Vsevolod,


Apologies for the delayed response, I'm not sure why this went unanswered for this long. To answer your question a custom query can be used to further refine the match making process. It allows you to query the participant data of a pending match. Here's a basic example for you using countries. You can try this yourself by opening two test harness windows and logging in as two different players.


  

//player one sends a MatchMakingRequest with the participantData set to {"country":"ireland"}
{
 "@class": ".MatchmakingRequest",
 "participantData": {"country":"ireland"},
 "matchShortCode": "testMatch",
 "skill": 2
} 

//player two then sends a MatchMakingRequest with the custom query set up to look for a match with the country set to Ireland.

{
 "@class": ".MatchmakingRequest",
 "customQuery": {"players.participantData.country":"ireland"},
 "matchData": {},
 "matchShortCode": "testMatch",
 "skill": 2
}

 

In this instance the players will be matched. If you were to repeat the process with player 2 set to query for the "UK" both players would get a MatchNotFoundMessage. I hope that clears that up for you. If you have any further questions just let us know.


Thanks,

Liam




2 people like this

very good answer but here i have another issue

the best way to make a custom match between 2 players is to make a custom query like this with id like this :

//player one sends a MatchMakingRequest with the participantData set to {"country":"ireland"}
{
 "@class": ".MatchmakingRequest",
 "Id": {"_Id":"...."},
 "matchShortCode": "testMatch",
 "skill": 2
} 

//player two then sends a MatchMakingRequest with the custom query set up to look for a match with the country set to Ireland.

{
 "@class": ".MatchmakingRequest",
 "customQuery": {"players.Id._Id":"...."},
 "matchData": {},
 "matchShortCode": "testMatch",
 "skill": 2
}

or the another way is on cloud code by adding the 2 players id like this :

var matchId = Spark.getMultiplayer().createMatchById(playerId1, playerId2);

Can you give an example of a MatchmakingRequest().SetCustomQuery(customQuery) in unity? Or should we use cloud code exclusively?

Example of Matchmaking request custom query in unity:
MatchmakingRequest request = new MatchmakingRequest();
request.SetMatchShortCode("CustomMatch");
request.SetSkill(0);
string jsonString = "{\"$in\":[\"5a58dd107eebc044b8ea0f57\"]}";
GSRequestData customQuery = new GSRequestData().AddJSONStringAsObject("players.playerId", jsonString);
request.SetCustomQuery(customQuery);
request.Send(OnMatchmakingSuccess, OnMatchmakingError);

 

The above custom query would be the equivalent of this in the test harness:
"customQuery":{"players.playerId":{"$in":["5a58dd107eebc044b8ea0f57"]}}
There are also more types you can add to the query. eg:
customQuery.AddInt("Key","asdf")

 


 




 

Login to post a comment