new CreateSFSGameRequest(settings)

Creates a new CreateSFSGameRequest instance. The instance must be passed to the SmartFox.send() method for the request to be executed.

This request creates a new Game Room in the current Zone through the istantiation of a SFSGame object on the server-side, a specialized Room type that provides advanced features during the creation phase of a game. Specific game-configuration settings are passed by means of the SFSGameSettings class.

If the creation is successful, a roomAdd event is dispatched to all the users who subscribed the Group to which the Room is associated, including the game creator. Otherwise, a roomCreationError event is returned to the creator's client.
Also, if the settings passed in the SFSGameSettings object cause invitations to join the game to be sent, an invitation event is dispatched to all the recipient clients.

Check the SmartFoxServer 2X documentation for a more in-depth overview of the GAME API.

Example

This example creates a new Game Room.

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_ADD, onRoomCreated, this);
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError, this);

	// Prepare the settings for a public game
	var settings = new SFS2X.SFSGameSettings("DartsGame");
	settings.maxUsers = 2;
	settings.maxSpectators = 8;
	settings.isPublic = true;
	settings.minPlayersToStartGame = 2;
	settings.notifyGameStarted = true;

	// Set the matching expression to filter users who can join the Room
	settings.playerMatchExpression = new SFS2X.MatchExpression("bestScore", SFS2X.NumberMatch.GREATER_THAN, 100);

	// Set a Room Variable containing the description of the game
	settings.variables = [new SFS2X.SFSRoomVariable("desc", "Darts game, public, bestScore > 100")];

	// Create the game
	sfs.send(new SFS2X.CreateSFSGameRequest(settings));
}

function onRoomCreated(evtParams)
{
	console.log("Room created: " + evtParams.room);
}

function onRoomCreationError(evtParams)
{
	console.log("Room creation failed: " + evtParams.errorMessage);
}

Parameter

Name Type Optional Description

settings

 

 

An object containing the Game Room configuration settings.

See also
SmartFox#send
SFSEvent.ROOM_ADD
SFSEvent.ROOM_CREATION_ERROR