Packagecom.electrotank.electroserver4.message.request
Classpublic class CreateRoomVariableRequest
InheritanceCreateRoomVariableRequest Inheritance com.electrotank.electroserver4.message.request.RequestImpl

This class allows you to create 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
  
Creates a new instance of the CrateRoomVariableRequest class.
CreateRoomVariableRequest
  
getLocked():Boolean
CreateRoomVariableRequest
  
getName():String
Returns the name of the new variable.
CreateRoomVariableRequest
  
getPersistent():Boolean
CreateRoomVariableRequest
  
getRoomId():Number
CreateRoomVariableRequest
  
Gets the EsObject value of the room variable.
CreateRoomVariableRequest
  
getZoneId():Number
CreateRoomVariableRequest
  
setLocked(locked:Boolean):void
The default is false.
CreateRoomVariableRequest
  
setName(name:String):void
Sets the name of the new room variable to crate.
CreateRoomVariableRequest
  
setPersistent(val:Boolean):void
CreateRoomVariableRequest
  
setRoomId(num:Number):void
CreateRoomVariableRequest
  
setValue(eob:EsObject):void
Sets the EsObject value of the room variable.
CreateRoomVariableRequest
  
setZoneId(num:Number):void
CreateRoomVariableRequest
  
CreateRoomVariableRequest
Constructor detail
CreateRoomVariableRequest()constructor
public function CreateRoomVariableRequest()

Creates a new instance of the CrateRoomVariableRequest class.

Method detail
getLocked()method
public function getLocked():Boolean

Returns
Boolean
getName()method 
public function getName():String

Returns the name of the new variable.

Returns
String — Returns the name of the new variable
getPersistent()method 
public function getPersistent():Boolean

Returns
Boolean
getRoomId()method 
public function getRoomId():Number

Returns
Number
getValue()method 
public function getValue():EsObject

Gets the EsObject value of the room variable.

Returns
EsObject — Returns the EsObject value of the room variable.
getZoneId()method 
public function getZoneId():Number

Returns
Number
setLocked()method 
public function setLocked(locked:Boolean):void

The default is false. If true, then the room variable cannot be udpated

Parameters
locked:Boolean — val
setName()method 
public function setName(name:String):void

Sets the name of the new room variable to crate.

Parameters
name:String — The name of the new variable.
setPersistent()method 
public function setPersistent(val:Boolean):voidParameters
val:Boolean
setRoomId()method 
public function setRoomId(num:Number):voidParameters
num:Number
setValue()method 
public function setValue(eob:EsObject):void

Sets the EsObject value of the room variable.

Parameters
eob:EsObject — The EsObject value of the room variable.
setZoneId()method 
public function setZoneId(num:Number):voidParameters
num:Number
validate()method 
public override function validate():ValidationResponse

Returns
ValidationResponse