Click or drag to resize

SetRoomVariablesRequest Class

Sets one or more custom Room Variables in a Room.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsSetRoomVariablesRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class SetRoomVariablesRequest : BaseRequest
Constructors
Remarks
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.
Examples
The following example sets a number of Room Variables and handles the respective update event:
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");         // UWP
        } else {
            Console.WriteLine("Game stopped");                          // .Net / Unity
            System.Diagnostics.Debug.WriteLine("Game stopped");         // UWP
        }
    }
}
See Also