Class: SFSUserVariable

SFSUserVariable


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

User Variables are particularly useful to assign any custom data to a user, such as his current in-game status, profile data, scoring, 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

User Variables are visibile to all users in the same Room. In other words all users in the same Room are able to read all other players' variables with the exclusion of those marked as hidden or private:

  • an hidden User Variable is only available on the server-side and never transmitted to other clients, including its owner;
  • a private User Variable is only visible to its owner and never transmitted to other clients, including those in the same Room of the owner.

Notes

See also


new SFSUserVariable(name, value [, type])

Creates a new SFSUserVariable 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 n = 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 User Variable.
value boolean | number | string | SFSObject | SFSArray The value of the User Variable; it can also be null.
type VariableType <optional>
null The type of the User Variable's value, among those listed in the VariableType enum; if null, type is autodetected.