Creates a new public or private game, including player matching criteria, invitations settings and more.

Namespace: Sfs2X.Requests.Game
Assembly: SmartFox2X (in SmartFox2X.dll) Version: (1.7.3)


public class CreateSFSGameRequest : BaseRequest


A game is created through the istantiation of a SFSGame 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 ROOM_ADD event is dispatched to all the users who subscribed the Group to which the Room is associated, including the game creator. Otherwise, a ROOM_CREATION_ERROR 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:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_ADD, OnRoomCreated);
    sfs.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, OnRoomError);
    // Prepare the settings for a public game
    SFSGameSettings settings = new SFSGameSettings("DartsGame");
    settings.MaxUsers = 2;
    settings.MaxSpectators = 8;
    settings.IsPublic = true;
    settings.MinPlayersToStartGame = 2;
    settings.NotifyGameStarted = true;
    // Set the matching expression to filter users joining the Room
    settings.PlayerMatchExpression = new MatchExpression("bestScore", NumberMatch.GREATER_THAN, 100);
    // Set a Room Variable containing the description of the game
    List<RoomVariable> roomVars = new List<RoomVariable>();
    roomVars.Add(new SFSRoomVariable("desc", "Darts game, public, bestScore > 100"));
    settings.variables = roomVars;
    // Create the game
    smartFox.Send( new CreateSFSGameRequest(settings) );
void OnRoomCreated(BaseEvent evt) {
    Console.WriteLine("Room created: " + (Room)evt.Params["room"]);                         // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room created: " + (Room)evt.Params["room"]);        // Windows Universal
void OnRoomError(BaseEvent evt) {
    Console.WriteLine("Room creation failed: " + (string)evt.Params["errorMessage"]);                           // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room creation failed: " + (string)evt.Params["errorMessage"]);          // Windows Universal

Inheritance Hierarchy


See Also