Packagecom.electrotank.electroserver4.entities
Classpublic class RoomVariable

This class is used to represent a room variable. A room variable is a variable scoped to a room that you are in and stored on the server. All users in your room receive these variables on entering the room, and receive create, update, and delete events on variables after they are already in the room.

Room variables have a string name and store an EsObject value. Room variables have the boolean properties of locked and persistent. The default values are locked=false and persistent=false. If locked=true, then the value cannot be modified until unlocked (it can still be deleted). If locked=false, then it can be modified. If persistent=false, then when the user that created it leaves the room the variable is removed. If persistent=true, then when the user leaves the room the variable stays.


Example
This example shows how to create a room variable and capture the event. The event is fired when a variable is created, updated, or deleted.
     import com.electrotank.electroserver4.ElectroServer;
    import com.electrotank.electroserver4.entities.RoomVariable;
    import com.electrotank.electroserver4.esobject.EsObject;
    import com.electrotank.electroserver4.message.event.RoomVariableUpdateEvent;
    import com.electrotank.electroserver4.message.MessageType;
    import com.electrotank.electroserver4.message.request.CreateRoomVariableRequest;
    import com.electrotank.electroserver4.room.Room;    
    //
    var es:ElectroServer;//Assume this was created, connection established, and login established already
    var myRoom:Room;//A reference to some room you are in.
    //
    function init():void {
        es.addEventListener(MessageType.RoomVariableUpdateEvent, "onRoomVariableUpdateEvent", this);
    }
    function createRoomVariable():void {
        //The value of the variable is an EsObject
        var eob:EsObject = new EsObject();
        eob.setString("LoopName", "Happy.mp3");
        eob.setInteger("Volume", 80);
        //
        var crr:CreateRoomVariableRequest = new CreateRoomVariableRequest();
        crr.setName("MusicInfo");
        crr.setValue(eob);
        crr.setRoomId(myRoom.getRoomId());
        crr.setZoneId(myRoom.getZone().getZoneId());
        crr.setLocked(false);
        crr.setPersistent(false);
        //
        es.send(crr);
    }
    function onRoomVariableUpdateEvent(e:RoomVariableUpdateEvent):void {
        //name of the variable affected
        var varName:String = e.getName();
        //reference to the room that holds the variable
        var room:Room = es.getZoneManager().getZoneById(e.getZoneId()).getRoomById(e.getRoomId());
        trace("Room variable name: "+varName);
        switch (e.getUpdateAction()) {
            case RoomVariableUpdateEvent.VariableCreated:
                trace("Variable created");
                var rv:RoomVariable = room.getRoomVariable(name);
                trace("Room variable value: "+rv.getValue());//Will just trace out an object reference of the EsObject;
                break;
            case RoomVariableUpdateEvent.VariableUpdated:
                trace("Variable updated");
                var rv:RoomVariable = room.getRoomVariable(name);
                trace("Room variable value: "+rv.getValue());//Will just trace out an object reference of the EsObject;
                break;
                break;
            case RoomVariableUpdateEvent.VariableDeleted:
                trace("Variable deleted");
                break;
            default:
                trace("Action not handled: "+e.getUpdateAction());
                break;
        }
    }
    init();
    createRoomVariable();
    



Public Methods
 MethodDefined by
  
RoomVariable(tmpname:String, tmpvalue:EsObject, perst:Boolean, lkd:Boolean)
This class is used to represent a room variable.
RoomVariable
  
getLocked():Boolean
Gets the variable's locked property.
RoomVariable
  
getName():String
Gets the variable name.
RoomVariable
  
getPersistent():Boolean
Returns the persistent property of the variable.
RoomVariable
  
Gets the variable value.
RoomVariable
  
setLocked(locked:Boolean):void
Sets the locked property of the variable.
RoomVariable
  
setName(name:String):void
Sets the variable name.
RoomVariable
  
setPersistent(persistent:Boolean):void
Sets the persistent property of the variable.
RoomVariable
  
setValue(value:EsObject):void
Sets the variable value.
RoomVariable
Constructor detail
RoomVariable()constructor
public function RoomVariable(tmpname:String, tmpvalue:EsObject, perst:Boolean, lkd:Boolean)

This class is used to represent a room variable. It is created internally to the API. Creating an instance of this class yourself isn't common.

Parameters
tmpname:String — Name of the variable.
 
tmpvalue:EsObject — EsObject value of the variable.
 
perst:Boolean — True or false. If true, then the variable will stay around after the user that created it leaves. If false, then the variable will die when the user leaves.
 
lkd:Boolean — True or false. If true, then the variable's value cannot be changed until unlocked. It can still be deleted when locked.
Method detail
getLocked()method
public function getLocked():Boolean

Gets the variable's locked property.

Returns
Boolean — True or false.
getName()method 
public function getName():String

Gets the variable name.

Returns
String — The variable name.
getPersistent()method 
public function getPersistent():Boolean

Returns the persistent property of the variable.

Returns
Boolean — True or false.
getValue()method 
public function getValue():EsObject

Gets the variable value.

Returns
EsObject — The variable value.
setLocked()method 
public function setLocked(locked:Boolean):void

Sets the locked property of the variable. If locked is true then the variable's value cannot be updated. If false it can be updated.

Parameters
locked:Boolean — True or false.
setName()method 
public function setName(name:String):void

Sets the variable name.

Parameters
name:String — The variable name.
setPersistent()method 
public function setPersistent(persistent:Boolean):void

Sets the persistent property of the variable. If persistent is true the variable remains when the user leaves the room, else it is removed.

Parameters
persistent:Boolean — True or false.
setValue()method 
public function setValue(value:EsObject):void

Sets the variable value.

Parameters
value:EsObject — The variable value.