Class SFS2X.Requests.System.SetRoomVariablesRequest

Sets one or more custom Room Variables in a Room.

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

Class Detail

SFS2X.Requests.System.SetRoomVariablesRequest(roomVariables, room)
Creates a new SetRoomVariablesRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

This request sets one or more custom Room Variables in a Room. When a Room Variable is set, the roomVariablesUpdate 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:

function someMethod()
{
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVarsUpdate, this);
	
	// Create some Room Variables
	var roomVars = [];
	roomVars.push(new SFS2X.Entities.Variables.SFSRoomVariable("gameStarted", false));
	roomVars.push(new SFS2X.Entities.Variables.SFSRoomVariable("gameType", "Snooker"));
	roomVars.push(new SFS2X.Entities.Variables.SFSRoomVariable("minRank", 10));
	
	sfs.send(new SFS2X.Requests.System.SetRoomVariablesRequest(roomVars));
}

function onRoomVarsUpdate(evtParams)
{
	var changedVars = evtParams.changedVars;
	var room = evtParams.room;
	
	// Check if the "gameStarted" variable was changed
	if (changedVars.indexOf("gameStarted") != -1)
	{
		if (room.getVariable("gameStarted").value == true)
			trace("Game started");
		else
			trace("Game stopped");
	}
}
Parameters:
{Array} roomVariables
A list of SFSRoomVariable objects representing the Room Variables to be set.
{SFSRoom} room Optional, Default: null
A SFSRoom object representing the Room where to set the Room Variables; if null, the last Room joined by the current user is used.
See also:
SFS2X.SmartFox#send
SFS2X.Entities.Variables.SFSRoomVariable
SFS2X.Entities.SFSRoom
SFS2X.SFSEvent.ROOM_VARIABLES_UPDATE