_server.setRoomVariables()

Availability:

SmartFoxServer PRO 1.4.0

Usage:

_server.setRoomVariables(room, who, varList, setOwnership, sendUpdate)

Description:

Set one or more Room Variables from the server side

Properties:

room  

the Room where the variables should be set

who   the User who wants to perform the action (null for Server owned variables)
varList  

a list of objects representing each variable. Each object has the following properties:


name   the variable name
val   variable value (undefined to delete an existing variable)
priv   true if the variable is private
persistent   true if the variable is persistent (will continue to exist when the user goes to another room. It is destroyed when the user closes the connection)

setOwnership   an optional boolean flag. By deafult is set to true. Set it to false to avoid to change the ownership of the variable(s)
sendUpdate   an optional boolean flag. By deafult is set to true. Set it to false to avoid sending an update to all clients in the room where the variables were changed.

Returns:

nothing

Example:

Example #1
var rVars = []
rVars.push( {name:"bestTime", val:100, priv:true} )
rVars.push( {name:"bestLap", val:120} )

// Set the variables
_server.setRoomVariables(roomObj, userObj, rVars)

Example #2
var rVars = []

rVars.push( {name:"highscore", val:12000, priv:true} )

// Set the variables
_server.setRoomVariables(roomObj, null, rVars)

In the above example a private "highscore" variable is set in the room, passing null as the variable owner.
This way no one will be able to overwrite the variable from the client side, as it belongs to the server and it is private.

See also: