_server.createRoom()
Availability:
SmartFoxServer PRO 1.4.0 / Refactored in version 1.4.5
Usage:
Version 1.4.0:
_server.createRoom(roomObj, user, sendUpdate, broadcastEvt)
Version 1.4.5 and higher:
_server.createRoom(roomObj, user, sendUpdate, broadcastEvt, roomVars, varsOwner, setOwnership)
Description:
Creates a new room.
Properties:
roomObj | an object describing the room properties. The following is a list of available properties:
For more info on the room configuration, please check this page |
||||||||||||||||||||||||||||
user | the User object of the client who is creating the room. If user is null the room will be "owned" by the Server and it will persist during all the server activity |
||||||||||||||||||||||||||||
sendUpdate | (optional) a boolean flag. By default it is set to true. If false the server won't send an update to the clients notifying the creation of the new room |
||||||||||||||||||||||||||||
broadcastEvt | (optional) a boolean flag. By default set to true. Used for broadcasting the server internal event that notifies the creation of a new room | ||||||||||||||||||||||||||||
roomVars | a list of objects representing each variable. Each object has the following
properties:
|
||||||||||||||||||||||||||||
varsOwner | the User who owns the variables (null for Server owned variables) | ||||||||||||||||||||||||||||
setOwnership | (optional) a boolean flag. By deafult is set to true. Set it to false to avoid to change the ownership of the variable(s) |
Returns:
the new Room object. If null is returned an error occured.
Example #1:
Create a room with a max of 25 users
/* * Create a new room owned by the server itself */ var roomObj = {} roomObj.name = "A new Room" roomObj.maxU = 25 var newRoom = _server.createRoom(roomObj, null) if (newRoom != null) trace("Great the room was created") else trace("A problem occurred, better check the server logs")
Example #2:
Create a game room with many different variables
/* * Create a new game room owned by the server */ // --- Room params ------------------------- var roomObj = {} roomObj.name = "TheGameRoom" roomObj.maxU = 10 roomObj.isGame = true // --- Vars -------------------------------- roomVars = [ {name:"Manufacturer", val:"Commodore", priv:true, persistent:true}, {name:"Model", val:"C64", priv:true, persistent:false}, {name:"CPU", val:"Motorola 6502", priv:true, persistent:true}, {name:"RAM", val:64, priv:true, persistent:true}, {name:"8-Bit", val:true, priv:false, persistent:true}, ] theRoom = _server.createRoom(roomObj, null, true, true, roomVars) if (theRoom != null) trace("Room Created Successfully") else trace("OUCH! Room was not created!!!")
See also: