Method

new SFSRoomVariable(name, value[, type])

Creates a new SFSRoomVariable instance.

A SFSRoomVariable 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 informations. They can be set by means of the SetRoomVariablesRequest request; they support the following data types (also nested): boolean, number, string, SFSObject, SFSArray. 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 will continue to exist even if its creator has left the Room (but will be deleted when the creator will get disconnected)
  • Global: a global Room Variable will fire update events not only to all users in the Room, but also to all users in the Group to which the Room belongs (NOTE: this flag is not available on the client-side because clients are not allowed to create global Room Variables)

Parameters

Name Type Optional Description

name

 

 

The name of the Room Variable.

value

 

 

The value of the Room Variable; it can also be null.

type

 

Yes

The type id of the Room Variable among those available in the VariableType class. Usually it is not necessary to pass this parameter, as the type is auto-detected from the value.

Defaults to -1.

Extends
BaseVariable
See also
VariableType
SFSRoom
SetRoomVariablesRequest

Properties

read-only

isNull  unknown

Indicates if the Variable is null.

Inherited from
BaseVariable#isNull

isPersistent  boolean

Indicates whether this Room Variable is persistent or not. A persistent Room Variable continues to exist in the Room after the user who created it has left it and until he disconnects.

NOTE: setting the isPersistent 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.

isPrivate  boolean

Indicates whether this Room Variable is private or not. A private Room Variable is visible to all users in the same Room, but it can be modified only by its owner (the user that created it).

NOTE: setting the isPrivate 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.

read-only

name  unknown

Indicates the name of this variable.

Inherited from
BaseVariable#name
read-only

type  unknown

Indicates the type of this Variable. Possibly returned strings are: null, boolean, int, double, string, SFSObject, SFSArray.

Inherited from
BaseVariable#type
read-only

value  unknown

Returns the value of this variable.

Inherited from
BaseVariable#value

Method

toString() → string

Returns a string that contains the Room Variable name, type, value and isPrivate flag.

Returns

string The string representation of the SFSRoomVariable object.