setRoomVariables()
Availability:
Flash Player 6.0
SmartFoxServer Lite / Basic / Pro
Usage:
smartFox.setRoomVariables(variables, roomId, setOwnership)
Description:
Stores data on the server side. When you set one or more Room
Variables all the other users in the room will be notified.
It is a usefull feature to share data across the client, keeping it in a centralized
place: the server.
Parameters:
variables | an array of variables. Each variable is an object with the following properties: | |
roomId | (optional) The id of the room where the variables are going to be stored. By default SmartFoxServer uses the current room, that is stored in the activeRoomId property. You can pass this extra argument if you are allowing users to be present in more than one room at the same time. |
|
setOwnership | A boolean flag, by default = true. If set to false the room variable won't change ownership. |
name | the variable name | |
val | value of the variable | |
priv | true if a variable is private. A private variable can only be overwritten by the user that created it | |
persistent | true if the variable is persistent. A persistent variable is not
destroyed when the user goes out of the room. The default behaviour deletes all the variables of a user that left the room |
Returns:
Fires the onRoomVariablesUpdate event
Example:
Example #1
save a persistent "score" room variable. This variable will not be destroyed
when the user that created it leaves the room.
var rVars = [] rVars.push( {name:"score", val:2500, persistent:true} ) smartFox.setRoomVariables(rVars)
var rVars = [] rVars.push( {name:"bestTime", val:100, priv:true} ) rVars.push( {name:"bestLap", val:120} ) smartFox.setRoomVariables(rVars)
var rVars = [] rVars.push( {name:"bestTime", val:null} ) smartFox.setRoomVariables(rVars)
var rVars = [] var names = ["john", "dave", "sam"] for (var i = 0; i < names.length; i++) { rVars.push( {name:"name" + i, val:names[i]} ) } smartFox.setRoomVariables(rVars)
smartFox.onRoomVariablesUpdate = function(roomVars) { for (var i = 0; i < 3; i++) { trace("name " + i + ": " + roomVars["name" + i]) } }
var rVars = [] rVars.push( {name:"shipPosX", val:100} ) rVars.push( {name:"shipPosY", val:200} )
smartFox.setRoomVariables(rVars, smartFox.getActiveRoom(), false)
See also:
onRoomVariablesUpdate