Class SFS2X.Requests.System.SetUserVariablesRequest
Sets one or more custom User Variables for the current user.
Constructor Attributes | Constructor Name and Description |
---|---|
SFS2X.Requests.System.SetUserVariablesRequest(userVariables)
Creates a new SetUserVariablesRequest instance.
|
Class Detail
SFS2X.Requests.System.SetUserVariablesRequest(userVariables)
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 ... } }
- Parameters:
- {Array} userVariables
- A list of SFSUserVariable objects representing the User Variables to be set.