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

Namespace: Sfs2X.Requests
Assembly: SmartFox2X (in SmartFox2X.dll) Version: (1.7.3)


public class SetUserVariablesRequest : BaseRequest


When a User Variable is set, the USER_VARIABLES_UPDATE event is dispatched to all the users in all the Rooms joined by the current user, including himself.

NOTE: the USER_VARIABLES_UPDATE 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:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, OnUserVarsUpdate);
    // Create some User Variables
    List<UserVariable> userVars = new List<UserVariable>();
    userVars.Add( new SFSUserVariable("avatarType", "SwedishCook") );
    userVars.Add( new SFSUserVariable("country", "Sweden") );
    userVars.Add( new SFSUserVariable("x", 10) );
    userVars.Add( new SFSUserVariable("y", 5) );
    sfs.Send( new SetUserVariablesRequest(userVars) );
void OnUserVarsUpdate(BaseEvent evt) {
    List<String> changedVars = (List<String>)evt.Params["changedVars"];
    User user = (User)evt.Params["user"];
    // Check if the user changed his x and y User Variables
    if (changedVars.Contains("x") || changedVars.Contains("y"))
        // Move the character to a new position...

Inheritance Hierarchy


See Also