Click or drag to resize

SetUserVariablesRequest Class

Sets one or more custom User Variables for the current user.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsSetUserVariablesRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class SetUserVariablesRequest : BaseRequest

The SetUserVariablesRequest type exposes the following members.

Constructors
  NameDescription
Public methodSetUserVariablesRequest
Creates a new SetUserVariablesRequest instance.
Top
Remarks
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).

Examples
The following example sets a number of User Variables and handles the respective update event:
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...
        UpdateClientPosition(user);
    }
}
See Also