SFSBuddyVariable

Represents a SmartFoxServer Buddy Variable entity on the client.


The Buddy Variable is a custom value attached to a SFSBuddy object in the Buddy List that gets automatically synchronized between client and server on every change.

Buddy Variables work with the same principle of the User and Room Variables. The only difference is the rationale that determines how they get propagated to other Uers. While Room and User Variables are usually broadcast to all clients in the same Room, Buddy Variables updates are sent to all Users which have the owner of the Buddy Variable in their Buddy Lists.

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

There is also a special convention that allows Buddy Variables to be set as "offline". Offline Buddy Variables are persistent values made available to all Users having the owner in their Buddy Lists, whether that Buddy is online or not. In order to make a Buddy Variable persistent, its name should start with a dollar sign ($). This conventional character is contained in the SFSBuddyVariable#OFFLINE_PREFIX constant.

Constructor

new SFSBuddyVariable(name, value, type)

Creates a new instance of the SFSBuddyVariable class.
Pass the instance to the SetBuddyVariablesRequest constructor.
Parameters:
NameTypeDescription
namestringThe name of the Buddy Variable.
valueboolean | number | string | SFSObject | SFSArray | SFSVector2 | SFSVector3The value of the Buddy Variable.
typenumberThe type of the Buddy Variable, among those available in the VariableType class.

Extends

Members

(constant) OFFLINE_PREFIX :string

Prefix to be added to the Buddy Variable name to make it persistent.

A persistent Buddy Variable is made available to all Users having the owner in their Buddy Lists, whether that Buddy is online or not.

Type:
  • string

(readonly) isNull :boolean

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

(readonly) isOffline :boolean

Indicates whether the Buddy Variable is persistent.

By convention, any Buddy Variable with a name starting with the dollar sign ($) is regarded as persistent and stored locally by the server.

Persistent Buddy Variables are also referred to as "offline variables" because they are available to all Users which have the Variable owner in their Buddy Lists, whether that Buddy is online or not.

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 that contains the Buddy Variable name, type and value.
Returns:
The string representation of the SFSBuddyVariable object.
Type: 
string