Constructor
new MatchExpression(varName, condition, varValue)
| Name | Type | Description |
|---|---|---|
varName | string | The name of the variable or property to match. |
condition | Matcher | The matching condition. |
varValue | boolean | | The value to compare against the variable or property during the matching. |
The following example shows how to create a simple matching expression made of two concatenated conditions: it compares the custom "rank" and "country" User Variables to the passed values. This expression could be used during the creation of a Game Room, to filter the Users that the server should take into account when sending the Invitations to join the game (only italian users with a ranking greater than 5 - whatever this number means to our game).
var exp = new MatchExpression('rank', NumberMatch.GREATER_THAN, 5)
.and('country', StringMatch.EQUALS, 'Italy');The following example creates a matching expression made of three concatenated conditions which compare two predefined Room properties and the custom "isGameStarted" Room Variable to the passed values; this expression could be used to retrieve all the Game Rooms still waiting for Players to join them.
var exp = new MatchExpression(RoomProperties.IS_GAME, BoolMatch.EQUALS, true)
.and(RoomProperties.HAS_FREE_PLAYER_SLOTS, BoolMatch.EQUALS, true)
.and('isGameStarted', BoolMatch.EQUALS, false);The following example creates a matching expression which compares a nested property in a complex data structure; an SFSObject called "avatarData" (could be a User Variable for example) contains the "shield" object (a nested SFSObject) which in turn contains, among others, the "inUse" property which could be used to retrieve all Users whose avatars are currently equipped with a shield.
var exp = new MatchExpression('avatarData.shield.inUse', BoolMatch.EQUALS, true);The following example is similar to the previous one, but it involves an SFSArray. The "avatarData" object contains the "weapons" SFSArray, from which the expression retrieves the third element (that .3 means "give me the element at index == 3") that we know being the weapon the avatar of the User has in its right hand. Again, this element is an SFSObject containing, among the others, the "name" property which can be compared to the passed string. This example could be used to retrieve all Users whose avatars have the Narsil sword in the right hand.
var exp = new MatchExpression('avatarData.weapons.3.name', StringMatch.EQUALS, "Narsil");Members
(readonly) condition :Matcher
Different objects extending the Matcher class can be used, depending on the type of the variable or property to check.
(readonly) logicOp :LogicOperator
- Default Value
- null
(readonly) next :MatchExpression
(readonly) varName :string
Depending what the matching expression is used for (searching a User or a Room), this can be the name of a SFSUserVariable or a SFSRoomVariable, or it can be one of the constants contained in the UserProperties or RoomProperties classes, representing some of the predefined properties of the User and Room entities respectively.
- string
(readonly) varValue :*
- *
Methods
and(varName, condition, varValue) → {MatchExpression}
| Name | Type | Description |
|---|---|---|
varName | string | The name of the additional variable or property to match. |
condition | Matcher | The additional matching condition. |
varValue | boolean | | The value to compare against the additional variable or property during the matching. |
- Type:
- MatchExpression
hasNext() → {boolean}
true if the current matching expression is concatenated to another matching expression.- Type:
- boolean
or(varName, condition, varValue) → {MatchExpression}
| Name | Type | Description |
|---|---|---|
varName | string | The name of the additional variable or property to match. |
condition | Matcher | The additional matching condition. |
varValue | boolean | | The value to compare against the additional variable or property during the matching. |
- Type:
- MatchExpression
rewind() → {MatchExpression}
- Type:
- MatchExpression
toString() → {string}
- Type:
- string