SFSRoomVariable

Represents a SmartFoxServer Room Variable entity on the client.


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

Room Variables are particularly useful to store custom Room data such as a game status and other Room-level information. Room Variables can be set by means of the SetRoomVariablesRequest; they support the data types listed in the VariableType class (also nested). A Room Variable can also be null.

Room Variables also support a number of specific flags:

  • Private: a private Room Variable can only be modified by its creator.
  • Persistent: a persistent Room Variable continues to exist even if its creator leaves the Room (but it's deleted when the creator gets disconnected).
  • Global: update events of global Room Variables are notified not only to all Users in the Room, but also to all clients which subscribed the Group to which the Room belongs. Note that this flag is not available on the client side because clients are not allowed to create global Room Variables.

Constructor

new SFSRoomVariable(name, value, type)

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

Extends

Members

(readonly) isNull :boolean

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

(readonly) isPersistent :boolean

Indicates whether the Room Variable is persistent.

A persistent Room Variable continues to exist in the Room after the User which created it has left the Room and until it disconnects.

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

Type:
  • boolean

(readonly) isPrivate :boolean

Indicates whether the Room Variable is private.

A private Room Variable is visible to all Users in the same Room, but it can be modified by its owner only (the User that created it).

Setting this property manually on an existing Room Variable returned by the API has no effect on the server and can disrupt the API functioning. This flag can be set after the Room 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 Room Variable type, name, value and private flag.
Returns:
The string representation of the SFSRoomVariable object.
Type: 
string