new SetRoomVariablesRequest(roomVariables[, room])

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

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.

Example

This 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.SFSRoomVariable("gameStarted", false));
	roomVars.push(new SFS2X.SFSRoomVariable("gameType", "Snooker"));
	roomVars.push(new SFS2X.SFSRoomVariable("minRank", 10));

	sfs.send(new SFS2X.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

Name Type Optional Description

roomVariables

 

 

A list of SFSRoomVariable objects representing the Room Variables to be set.

room

 

Yes

A SFSRoom object representing the Room where to set the Room Variables; if null, the last Room joined by the current user is used.

Defaults to null.

See also
SmartFox#send
SFSEvent.ROOM_VARIABLES_UPDATE