Class SFS2X.Requests.Game.QuickJoinGameRequest

Quickly joins the current user in a public game.

Class Summary
Constructor Attributes Constructor Name and Description
 
SFS2X.Requests.Game.QuickJoinGameRequest(matchExpression, whereToSearch, roomToLeave)
Creates a new QuickJoinGameRequest instance.

Class Detail

SFS2X.Requests.Game.QuickJoinGameRequest(matchExpression, whereToSearch, roomToLeave)
Creates a new QuickJoinGameRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Using this request, by providing a matching expression and a list of Rooms or Groups, SmartFoxServer can search for a matching public Game Room and immediately join the user into that Room as a player.

If a game is found and can be joined, the roomJoin event is dispatched to the requester's client.

The following example creates a new game:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoin, this);
	
	// Create a matching expression to find a Darts game with a "maxBet" variable less than 100
	var exp = new SFS2X.Entities.Match.MatchExpression("type", SFS2X.Entities.Match.StringMatch.EQUALS, "darts").and("maxBet", SFS2X.Entities.Match.NumberMatch.LESS_THAN, 100);
	
	// Search and join a public game within the "games" Group, leaving the last joined Room
	sfs.send(new SFS2X.Requests.Game.QuickJoinGameRequest(exp, ["games"], sfs.lastJoinedRoom));
}

function onRoomJoin(evtParams)
{
	console.log("Successfully joined Room: " + evtParams.room);
}
Parameters:
{MatchExpression} matchExpression Optional, Default: null
A matching expression that the system will use to search a Game Room where to join the current user.
{Array} whereToSearch
An array of SFSRoom objects or an array of Group names to which the matching expression should be applied. The maximum number of elements that this array can contain is 32.
{SFSRoom} roomToLeave Optional, Default: null
A SFSRoom object representing the Room that the user should leave when joining the game.
See also:
SFS2X.SmartFox#send
SFS2X.Entities.Match.MatchExpression
SFS2X.Entities.SFSRoom
SFS2X.SFSEvent.ROOM_JOIN