Contents

Expressions

Write expressions that query the match requests in a queue to find the best players for a match.

Overview

An expression is a JMESPath formatted string with additional matchmaking rule functions. Game Center uses the expression to query a collection of match requests represented as JSON. The expression needs to evaluate to either a Boolean or number value according to the rule type.

To create a matchmaking rule in Game Center, you pass an expression to the Create a rule endpoint. Set the expression and type fields of the GameCenterMatchmakingRuleCreateRequest.Data.Attributes object that you pass in the request.

For example, if players can only join matches that run the same version of your game, add a compatible rule that compares the app versions. If you set the rule’s type field to COMPATIBLE, the requests array in the JSON input to the expression contains two match requests to compare. In the expression, use the areCompatibleAppVersions() function that returns true if the app versions are compatible.

areCompatibleAppVersions(requests[0], requests[1])

You can improve the game experience by prioritizing matches between players who are geographically close, resulting in lower latency when sending messages between devices. If you set the rule’s type field to DISTANCE, the requests array in the expression contains two match requests to compare. In the expression, use the geoLatency() function that returns a range between 0.0 and 1.0, where 0.0 is in the local area:

geoLatency(requests[0], requests[1])

The JSON input to an expression contains the following arrays, that you can use in expressions, depending on the rule type:

Array

Description

players

An array of Player objects representing the players associated with the requests. [Image] Available in all types of rule expressions.

requests

An array of Request objects representing the match requests that you compare in an expression. [Image] Available in all types of rule expressions. In compatible and distance rules, contains two items for comparison. In match and team rules, contains two or more items.

teams

An array of Team objects representing the teams that you add to a rule set, including the players assigned to the teams. [Image] Available only in team rule expressions.

Topics

Comparison functions

Distance functions

Match functions

Team functions

Boolean functions

Numeric functions

Array functions

Objects

See Also

Matchmaking rules