public class SFSUserVariable extends java.lang.Object implements UserVariable
UserVariables support basic data types and nested complex objects:
UserVariables are visibile among users in the same Room. In other words all Users in the same Room will be able to read all other player's variables with the exclusion of those marked as hidden or private.
NOTE: Private User Variables are available since SFS2X 2.12.0 and require a Client API version 1.7 or higher.
An easy way to create a private UserVariable is this:
UserVariable privateVar = SFSUserVariable.newPrivateVariable("Name", "My Value");
Modifier and Type | Field and Description |
---|---|
protected boolean |
hidden |
protected java.lang.String |
name |
protected boolean |
priv |
protected boolean |
storable |
protected VariableType |
type |
protected java.lang.Object |
value |
Modifier | Constructor and Description |
---|---|
protected |
SFSUserVariable(java.lang.String name) |
|
SFSUserVariable(java.lang.String name,
java.lang.Object value)
Create a new UserVariable
|
|
SFSUserVariable(java.lang.String name,
java.lang.Object value,
boolean isHidden)
Create a new UserVariable
|
|
SFSUserVariable(java.lang.String name,
java.lang.Object value,
boolean isHidden,
boolean isPrivate)
Create a new UserVariable
|
protected |
SFSUserVariable(java.lang.String name,
java.lang.String type,
java.lang.String literal) |
protected |
SFSUserVariable(java.lang.String name,
VariableType type,
java.lang.String literal) |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
java.lang.Boolean |
getBoolValue()
Get the value of the variable as Boolean
|
java.lang.Double |
getDoubleValue()
Get the value of the variable as Double
|
java.lang.Integer |
getIntValue()
Get the value of the variable as Integer
|
java.lang.String |
getName() |
ISFSArray |
getSFSArrayValue()
Get the value of the variable as SFSArray
|
ISFSObject |
getSFSObjectValue()
Get the value of the variable as SFSObject
|
java.lang.String |
getStringValue()
Get the value of the variable as String
|
VariableType |
getType()
Return the data type of the variable
|
java.lang.Object |
getValue()
Get the value of the variable as Object
|
boolean |
isHidden()
Checks if the variable is "hidden".
|
boolean |
isNull()
Test if a variable is null
|
boolean |
isPrivate()
Checks whether a UserVariable is private.
|
boolean |
isStorable()
Storable variables can be saved by the Room Persistence API
|
static SFSUserVariable |
newFromSFSArray(ISFSArray array)
SFSArray is expected to be formatted as follows
0: (str) -> name
1: (byte) -> type id
2: (Object) -> value
3: (bool) -> isPrivate
|
static SFSUserVariable |
newFromStringLiteral(java.lang.String name,
java.lang.String type,
java.lang.String literal) |
static SFSUserVariable |
newInstance(java.lang.String name,
java.lang.Object value) |
static SFSUserVariable |
newPrivateVariable(java.lang.String name,
java.lang.Object value) |
protected void |
populateArrayWithValue(ISFSArray sfsa)
Populate an SFSArray wih the typed value of this Variable
|
void |
setHidden(boolean flag)
Set the variable as "hidden".
|
void |
setNull()
This is used by the system to mark removed variables.
|
void |
setPrivate(boolean value)
Setting a UserVariable as private restricts its visibility to the owner only.
|
void |
setStorable(boolean value)
Flags this variable as storable (default = true).
|
protected void |
setValue(java.lang.Boolean val) |
protected void |
setValue(java.lang.Double val) |
protected void |
setValue(java.lang.Integer val) |
protected void |
setValue(ISFSArray val) |
protected void |
setValue(ISFSObject val) |
protected void |
setValue(java.lang.Object val) |
protected void |
setValue(java.lang.String val) |
protected void |
setValueFromStringLiteral(VariableType type,
java.lang.String literal) |
ISFSArray |
toSFSArray()
Private
|
java.lang.String |
toString() |
protected java.lang.String name
protected volatile java.lang.Object value
protected VariableType type
protected boolean hidden
protected boolean priv
protected boolean storable
public SFSUserVariable(java.lang.String name, java.lang.Object value)
name
- name of the variablevalue
- value of the variable (using any of the supported types)public SFSUserVariable(java.lang.String name, java.lang.Object value, boolean isHidden, boolean isPrivate)
name
- name of the variablevalue
- value of the variableisHidden
- true if the variable needs to be server-side onlyisPrivate
- true if the variable will only be seen by it's owner (other users are not updated)public SFSUserVariable(java.lang.String name, java.lang.Object value, boolean isHidden)
name
- name of the variablevalue
- value of the variableisHidden
- true if the variable needs to be server-side onlyprotected SFSUserVariable(java.lang.String name)
protected SFSUserVariable(java.lang.String name, VariableType type, java.lang.String literal)
protected SFSUserVariable(java.lang.String name, java.lang.String type, java.lang.String literal)
public static SFSUserVariable newInstance(java.lang.String name, java.lang.Object value)
public static SFSUserVariable newFromStringLiteral(java.lang.String name, java.lang.String type, java.lang.String literal)
public static SFSUserVariable newFromSFSArray(ISFSArray array)
array
- public static SFSUserVariable newPrivateVariable(java.lang.String name, java.lang.Object value)
public boolean isHidden()
isHidden
in interface UserVariable
UserVariable.setHidden(boolean)
public void setHidden(boolean flag)
setHidden
in interface UserVariable
public boolean isPrivate()
isPrivate
in interface UserVariable
public void setPrivate(boolean value)
When the flag is false, the UserVariable will be visible by all users in the same Room.
setPrivate
in interface UserVariable
value
- protected void setValueFromStringLiteral(VariableType type, java.lang.String literal)
public VariableType getType()
getType
in interface Variable
VariableType
public java.lang.Boolean getBoolValue()
getBoolValue
in interface Variable
public java.lang.Double getDoubleValue()
getDoubleValue
in interface Variable
public java.lang.Integer getIntValue()
getIntValue
in interface Variable
public ISFSArray getSFSArrayValue()
getSFSArrayValue
in interface Variable
public ISFSObject getSFSObjectValue()
getSFSObjectValue
in interface Variable
public java.lang.String getStringValue()
getStringValue
in interface Variable
public java.lang.Object getValue()
public boolean isNull()
public void setNull()
setNull
in interface UserVariable
protected void setValue(java.lang.Boolean val)
protected void setValue(java.lang.Double val)
protected void setValue(java.lang.Integer val)
protected void setValue(ISFSArray val)
protected void setValue(ISFSObject val)
protected void setValue(java.lang.Object val)
public ISFSArray toSFSArray()
Variable
toSFSArray
in interface Variable
public boolean isStorable()
isStorable
in interface UserVariable
public void setStorable(boolean value)
setStorable
in interface UserVariable
protected void populateArrayWithValue(ISFSArray sfsa)
sfsa
- the SFSArray
protected void setValue(java.lang.String val)
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object