Sets one or more custom Room Variables in a Room.

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


public class SetRoomVariablesRequest : BaseRequest


When a Room Variable is set, the ROOM_VARIABLES_UPDATE event is dispatched to all the users in the target Room, including the user who updated it. Also, if the Room Variable is global (see the SFSRoomVariable class description), the event is dispatched to all users who subscribed the Group to which the target Room is associated.


The following example sets a number of Room Variables and handles the respective update event:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, OnRoomVarsUpdate);
    // Create some Room Variables
    List<RoomVariable> roomVars = new List<RoomVariable>();
    roomVars.Add( new SFSRoomVariable("gameStarted", false) );
    roomVars.Add( new SFSRoomVariable("gameType", "Snooker") );
    roomVars.Add( new SFSRoomVariable("minRank", 10) );
    sfs.Send( new SetRoomVariablesRequest(roomVars) );
void OnRoomVarsUpdate(BaseEvent evt) {
    List<String> changedVars = (List<String>)evt.Params["changedVars"];
    Room room = (Room)evt.Params["room"];
    // Check if the gameStarted variable was changed
    if (changedVars.Contains ("gameStarted")) {
        if (room.GetVariable("gameStarted").GetBoolValue()) {
            Console.WriteLine("Game started");                          // .Net / Unity
            System.Diagnostics.Debug.WriteLine("Game started");         // Windows Universal
        } else {
            Console.WriteLine("Game stopped");                          // .Net / Unity
            System.Diagnostics.Debug.WriteLine("Game stopped");         // Windows Universal

Inheritance Hierarchy


See Also