Class SFS2X.Requests.System.SetUserVariablesRequest

Sets one or more custom User Variables for the current user.

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

Class Detail

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

This request sets one or more User Variables for the current user. When a User Variable is set, the userVariablesUpdate event is dispatched to all the users in all the Rooms joined by the current user, including himself.

NOTE: the userVariablesUpdate event is dispatched to users in a specific Room only if it is configured to allow this event (see the RoomSettings.permissions parameter).

The following example sets a number of User Variables and handles the respective update event:

function someMethod()
	sfs.addEventListener(SFS2X.SFSEvent.USER_VARIABLES_UPDATE, onUserVarsUpdate, this);
	// Create some User Variables
	var userVars = [];
	userVars.push(new SFS2X.Entities.Variables.SFSUserVariable("avatarType", "SwedishCook"));
	userVars.push(new SFS2X.Entities.Variables.SFSUserVariable("country", "Sweden"));
	userVars.push(new SFS2X.Entities.Variables.SFSUserVariable("x", 10));
	userVars.push(new SFS2X.Entities.Variables.SFSUserVariable("y", 5));
	sfs.send(new SFS2X.Requests.System.SetUserVariablesRequest(userVars));

function onUserVarsUpdate(evtParams)
	var changedVars = evtParams.changedVars;
	var user = evtParams.user;
	// Check if the user changed his x and y user variables
	if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1)
		// Move the user avatar to a new position
{Array} userVariables
A list of SFSUserVariable objects representing the User Variables to be set.
See also: