Class SFSRoomVariable
java.lang.Object
com.smartfoxserver.entities.variables.BaseVariable
com.smartfoxserver.entities.variables.SFSUserVariable
com.smartfoxserver.entities.variables.SFSRoomVariable
- All Implemented Interfaces:
RoomVariable,UserVariable,Variable,Serializable,Cloneable
RoomVariables are custom values assigned to Room objects that get automatically synchronized between client and server
on every change. They are particularly useful to assign custom data such game state, or specific properties to keep track of the current game, especially in turn-based
scenarios.
RoomVariables support a number of different data types:
- Null
- Bool
- Byte
- Short
- Int
- Long
- Float
- Double
- Vector2
- Vector3
- String
- SFSObject
- SFSArray
RoomVariables also support different flags:
- Private: a private variable can only be modified by its owner/creator
- Persistent: a persistent variable will continue to exist even if its creator has left the Room. Server-created RoomVariables are never be autom-removed
- Global: a global variable trigger updates not only to all Users in the Room but also to Users subscribed to the the Room's Group
- Hidden: an hidden variable is be kept on the server side only and can't be created or accessed from the client side
- Storable: all variables are storable by default. When the flag is turned off the Room Persistence API will ignore the variable
- See Also:
-
Field Summary
Fields inherited from class com.smartfoxserver.entities.variables.SFSUserVariable
hidden, priv, storableFields inherited from class com.smartfoxserver.entities.variables.BaseVariable
name, type, value -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSFSRoomVariable(String name) SFSRoomVariable(String name, Object value) Create a new Room VariableSFSRoomVariable(String name, Object value, boolean isPrivate, boolean isPersistent, boolean isGlobal) Create a new Room VariableprotectedSFSRoomVariable(String name, String type, String literal) -
Method Summary
Modifier and TypeMethodDescriptiongetOwner()Return the User that created the variable.booleanisGlobal()Checks if a RoomVariable is global.booleanChecks if a RoomVariable is persistentbooleanChecks if a RoomVariable is private.static SFSRoomVariablenewFromSFSArray(ISFSArray array) static SFSRoomVariablenewFromStringLiteral(String name, String type, String literal) voidsetGlobal(boolean flag) When a RoomVariable is set to global all changes will be broadcast not only to the Users in the Room but also to all other Users in the same Room GroupvoidSets the creator of a variable.voidsetPersistent(boolean flag) When a RoomVariable is set to persistent the variable will not be removed from a Room when the user leaves it.voidsetPrivate(boolean flag) When a RoomVariable is set to private only its owner can modify or delete it.toString()Methods inherited from class com.smartfoxserver.entities.variables.SFSUserVariable
clone, isHidden, isStorable, newPrivateVariable, setHidden, setStorableMethods inherited from class com.smartfoxserver.entities.variables.BaseVariable
getBoolValue, getByteValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getName, getSFSArrayValue, getSFSObjectValue, getShortValue, getStringValue, getType, getValue, getVector2Value, getVector3Value, isNull, populateArrayWithValue, setNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromStringLiteralMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.smartfoxserver.entities.variables.UserVariable
isHidden, isStorable, setHidden, setNull, setStorableMethods inherited from interface com.smartfoxserver.entities.variables.Variable
getBoolValue, getByteValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getName, getSFSArrayValue, getSFSObjectValue, getShortValue, getStringValue, getType, getValue, getVector2Value, getVector3Value, isNull
-
Constructor Details
-
SFSRoomVariable
-
SFSRoomVariable
-
SFSRoomVariable
Create a new Room Variable- Parameters:
name- the variable namevalue- the variable value (see supported data types at the top)
-
SFSRoomVariable
public SFSRoomVariable(String name, Object value, boolean isPrivate, boolean isPersistent, boolean isGlobal) Create a new Room Variable- Parameters:
name- the variable namevalue- the variable value (see supported data types at the top)isPrivate- the private flagisPersistent- the persistent flagisGlobal- the global flag
-
-
Method Details
-
newFromStringLiteral
- Internal
-
newFromSFSArray
- Internal
-
isGlobal
public boolean isGlobal()Checks if a RoomVariable is global. Global RV are visible outside of the Room and available to all Users subscribed to its Room Group- Specified by:
isGlobalin interfaceRoomVariable- Returns:
- true if the variable is global
- See Also:
-
isPersistent
public boolean isPersistent()Checks if a RoomVariable is persistent- Specified by:
isPersistentin interfaceRoomVariable- Returns:
- true if the variable is persistent
- See Also:
-
isPrivate
public boolean isPrivate()Checks if a RoomVariable is private. Private Room variables are visible to all Users in the Room but only the owner can modify or delete them.- Specified by:
isPrivatein interfaceUserVariable- Overrides:
isPrivatein classSFSUserVariable- Returns:
- true if the variable is private
- See Also:
-
setGlobal
public void setGlobal(boolean flag) When a RoomVariable is set to global all changes will be broadcast not only to the Users in the Room but also to all other Users in the same Room Group- Specified by:
setGlobalin interfaceRoomVariable- Parameters:
flag-
-
setPersistent
public void setPersistent(boolean flag) When a RoomVariable is set to persistent the variable will not be removed from a Room when the user leaves it. RoomVariables created by a certain User are removed when the User disconnects- Specified by:
setPersistentin interfaceRoomVariable- Parameters:
flag-
-
setPrivate
public void setPrivate(boolean flag) When a RoomVariable is set to private only its owner can modify or delete it.- Specified by:
setPrivatein interfaceUserVariable- Overrides:
setPrivatein classSFSUserVariable- Parameters:
flag-
-
getOwner
Return the User that created the variable. Null is returned if the variable is owned by the Server- Specified by:
getOwnerin interfaceRoomVariable- Returns:
- the variable owner
-
setOwner
Sets the creator of a variable. Null can be used to set the Server as the owner. When a variable is owned by the Server it will never be removed.- Specified by:
setOwnerin interfaceRoomVariable- Parameters:
user-
-
getOwnerAsString
- Internal
-
toSFSArray
- Specified by:
toSFSArrayin interfaceVariable- Overrides:
toSFSArrayin classSFSUserVariable- Internal
-
toString
- Overrides:
toStringin classSFSUserVariable
-