Room class
Availability:
SmartFoxServer PRO 1.2.1
Description:
A Rom object represents a room running in a specific Zone.
Here follows a list of public methods for this object.
Public Methods:
contains(userName) | Return true if the passed userName exist in the room | |
getAllUsers() | Return an array with all the users | |
getId() | Return the id of the room | |
getMaxSpectator() | Return the max. amount of spectators allowed | |
getMaxUsers() | Return the max. number of users allowed in the room | |
getName() | Return the room name | |
getPassword() | Return the room password | |
getSpectatorCount() | Return the current number of spectators | |
getUserCount() | Return the current number of users | |
getVariable(name) | Return the room variable with the requested name | |
getVariables() | Return a java.util.HashMap with all the Room Variables | |
isGame() | Return true if the room is a game room | |
isPrivate() | Return true if the room is private | |
isTemp() | Return true if the room is temporary (dynamic) |
Public Properties:
It is also possible to "attach" your own custom properties to the Room() object by using the public "properties" object. The object works like an associative array. Below follows a list of methods available:put(key, value) | Put a new value/object | |
get(key) | Retrive the value/object for the passed key. If the object doesn't exist it returns null | |
remove(key) | Remove the value/object | |
size() | Return the size of the properties array |
var score = 2500 var bestScore = 31000 var bestPlayers = ["Jim", "Pat", "Hal", "Sam", "Tom"] // Save data in the room.properties associative array room.properties.put("score", score) room.properties.put("bestScore", bestScore) room.properties.put("bestPlayers", bestPlayers) // Retrieve data and display it var list = room.properties.get("bestPlayers") for (var i in list) trace("Name: " + list[i])
Example #2: variables
/** * Obtain the list of variables in the room * * the getVariable() method will return a java native HashMap object (java.util.HashMap) * You can read the javadoc here: http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html */ var rVars = roomObject.getVariables() // We cycle through the HashMap and trace each variable for (var i = rVars.entrySet().iterator(); i.hasNext();) { var rVar = i.next() var varName = rVar.getKey() var varValue = rVar.getValue().getValue() trace("var: " + varName + ", val: " + varValue) }
An HashMap is like an associative array, so each values is stored with its own
key.
The entrySet() method returns a set of objects with a getKey() and getValue()
methods.
The variable name is stored in the key of the array
The variable itself is the value.