Class SFS2X.Requests.Game.CreateSFSGameRequest

Creates a new public or private Game Room in the current Zone, including player matching criteria, invitations settings and more.

Class Summary
Constructor Attributes Constructor Name and Description
Creates a new CreateSFSGameRequest instance.

Class Detail

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

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.

The following example creates a new game:

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.Requests.Game.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.Entities.Match.MatchExpression("bestScore", SFS2X.Entities.Match.NumberMatch.GREATER_THAN, 100);
	// Set a Room Variable containing the description of the game
	settings.variables = [new SFS2X.Entities.Variables.SFSRoomVariable("desc", "Darts game, public, bestScore > 100")];
	// Create the game
	sfs.send(new CreateSFSGameRequest(settings));

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

function onRoomCreationError(evtParams)
	console.log("Room creation failed: " + evtParams.errorMessage);
{SFSGameSettings} settings
An object containing the Game Room configuration settings.
See also: