Hi Matteo,
You would need two components to make this work:
1) Valid player scriptData.
2) An event which will fire a matchmaking request using the player's scriptData.
Valid Script Data:
What I mean by this is having those values level, league and Available declared and assigned on the player using Spark.getPlayer().setScriptData().
A good place to have this is when the player registers, either in Authentication response (If you're using social and device authentication) or registration response (if using registration request).
When those values are in your player's scriptData (Personal record/Database) you can use them to run your custom logic.
Cloud Code to run matchmaking:
Because these values are on our players, we want to retrieve them and use them in our request without having to manually input the values in. So we'll need to create a log event request and attach some cloud code to it which will automatically assign values to our request.
Here's some cloud code to better explain how this will work:
//Create request var matchRequest = new SparkRequests.MatchmakingRequest(); //ShortCode matchRequest.matchShortCode = "myMatchShortCode" //Skill matchRequest.skill = Spark.getPlayer().getScriptData("skill") //The query the the match will look for. This is not a suggestion, the participant data must comply. This cant be a hard set value or input from the event matchRequest.customQuery = {"level":"some hard value","league":Spark.getData().eventAttributeInput,"availableToPlay":true} //The matcih data that will be compared with custom query matchRequest.matchData = {"level":Spark.getPlayer().getScriptData("level"),"league":Spark.getPlayer().getScriptData("league"), "availableToPlay":Spark.getPlayer().getScriptData("availableToPlay")}; //If you dont care about the response matchRequest.Send() //if you want to output the response Spark.setScriptData("response", matchRequest.Send())
This will work if your matchData is exactly the same across all players (Which you will want). This is because when two pending matches are combined (Two players find a match) the matchData of the new match will be a random selection of one of their matchDatas.
Hope this helps and sheds some more light on what you need to do.
Cheers,
Omar
Hello Omar,
thanks for the reply.
I figured to have the custom data "(status", "AvailableToPlay") saved to a player (as suggested here:)
but the matchRequest returns the following error when i try to specify it in the matchRequest.customQuery:
"message": "Unrecognized field \"status\" (class com.gamesparks.messages.requests.MatchmakingRequest), not marked as ignorable (17 known properties: \"matchShortCode\", \"sessionCloseNotifier\", \"requestId\", \"remoteHost\", \"matchData\", \"analyticsData\", \"authToken\", \"debug\", \"scriptData\", \"action\", \"customQuery\", \"matchGroup\", \"playerId\", \"participantData\", \"redirectBuilder\", \"sessionId\", \"skill\"])\n at [Source: { \"@class\" : \".MatchmakingRequest\" , \"matchShortCode\" : \"myMatchShortCode\" , \"status\" : \"available\" , \"customQuery\" : { \"status\" : \"available\"} , \"matchData\" : { \"status\" : \"available\"}}; line: 1, column: 90] (through reference chain: com.gamesparks.messages.requests.MatchmakingRequest[\"status\"])"
Hi,
in my game i matched two players in turn based game and both players have got matchfound message and also challengestarted message. When players get challengestarted i want to send a value (a paramater that will be the input for the function in cloud script) to cloud to make function in the script run.
But when i send the value with logchallengeventrequest, turn mechanism is working and one of the player cannot send the value, so the game logic cannot start.
When i send the value with logeventchallenge, i can take the value and run the function, but after that i cannot store the return parameter of the function to the database which the unique ID is challengeInstanceID. I cannot reach challengeID from LogEvent script.
So how can i send the value that consider game logic?
I need that value from the clients and in cloud i need to store some value calculated from that value. So the game will start.
Matteo Grossi
Hello,
i would like to save some custom data into a player's profile, and then use it in the matchmaking process.
For example, i want to store in the player data a value that keep track if the player is available for a new challenge (this value would be true when the player completed a challenge he was playing in or when he is not already in another challenge).
Assuming another player create a new challenge with 10 participants, all participants must match different criteria (Level, League, AvailableForChallenge (true)).
What would the best approach be, and what do you recommend?
Thanks!