SFSUserVariable

Represents a SmartFoxServer User Variable entity on the client.


The User Variable is a custom value attached to a User object that gets automatically synchronized between client and server on every change.

User Variables are particularly useful to store custom User data that must be "visible" to the other Users, such as profile details, a score, a status message, etc. User Variables can be set by means of the SetUserVariablesRequest; they support the data types listed in the VariableType class (also nested). A User Variable can also be null.

User Variables can be private: this flag allows to limit the visibility of User Variables to their owner only. In other words User Variables marked as private are not sent to other Users, even if located in the same Room.

Constructor

new SFSUserVariable(name, value, type)

Creates a new instance of the SFSUserVariable class.
Pass the instance to the SetUserVariablesRequest constructor.
Parameters:
NameTypeDescription
namestringThe name of the User Variable.
valueboolean | number | string | SFSObject | SFSArrayThe value of the User Variable.
typenumberThe type of the User Variable, among those available in the VariableType class.

Extends

Members

(readonly) isNull :boolean

Indicates whether the Variable has a null value.
Type:
  • boolean

isPrivate :boolean

Indicates whether this User Variable is private.

A private User Variable is visible only to its owner; any changes made to the variable will be transmitted to the owner only.

Setting this property manually on an existing User Variable returned by the API has no effect on the server and can disrupt the API functioning. This flag can be set after the User Variable object is created using the constructor only.

Type:
  • boolean

(readonly) name :string

Name of the Variable.
Type:
  • string

(readonly) type :string

Type of the Variable.

Returned value is the name of one of the types defined in the VariableType class.

Type:
  • string

(readonly) value :*

Value of the Variable.
Type:
  • *

Methods

toString() → {string}

Returns a string containing the User Variable type, name, value and private flag.
Returns:
The string representation of the SFSUserVariable object.
Type: 
string