new SetUserVariablesRequest(userVariables)

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

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).

Example

This 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.SFSUserVariable("avatarType", "SwedishCook"));
	userVars.push(new SFS2X.SFSUserVariable("country", "Sweden"));
	userVars.push(new SFS2X.SFSUserVariable("x", 10));
	userVars.push(new SFS2X.SFSUserVariable("y", 5));

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

Parameter

Name Type Optional Description

userVariables

 

 

A list of SFSUserVariable objects representing the User Variables to be set.

See also
SmartFox#send
SFSEvent.USER_VARIABLES_UPDATE