Class: SFSRoomVariable

SFSRoomVariable


The SFSRoomVariable class represents a Room Variable, a custom value attached to a Room object that gets automatically updated between client and server on every change.

Room Variables are particularly useful to "attach" any custom data to a Room, such as the current game status in a game Room, the topic in chat Room, other Room-specific properties, etc.
They support basic data types and nested complex objects:

  • null
  • boolean
  • int (32 bit integer)
  • double (64 bit double precision number)
  • utf-string (UTF-8 encoded string, with length up to 32 KBytes)
  • SFSObject
  • SFSArray

Room Variables support a few different flags:

  • a private Room Variable can only be modified by its creator;
  • a persisten Room Variable continues to exist even if its creator has left the Room; server-created Room Variables are removed;
  • a global Room Variable change causes an update event to be sent not only to all users in the Room, but also to all users in the Room Group to which the Room belongs;
  • an hidden Room Variable is only available on the server-side and never transmitted to the clients.

Notes

See also


new SFSRoomVariable(name, value [, type])

Creates a new SFSRoomVariable instance.

Although the third parameter is optional, it is strongly recommended to use it. The reason is type autodetection of numbers (being integers or double precision numbers) may fail in some corner cases (for example n1 = Math.floor(100.0 - 99.0) will be treated as a double instead of an integer as expected).

Parameters:
Name Type Argument Default Description
name string The name of the Room Variable.
value boolean | number | string | SFSObject | SFSArray The value of the Room Variable; it can also be null.
type VariableType <optional>
null The type of the Room Variable's value, among those listed in the VariableType enum; if null, type is autodetected.