Packagecom.electrotank.electroserver4.message.request
Classpublic class UpdateUserVariableRequest
InheritanceUpdateUserVariableRequest Inheritance com.electrotank.electroserver4.message.request.RequestImpl

This request allows you to create or update a user variable on yourself. A user variable is a name value pair stored on the server and scoped to a user. The name is a string and the value is an EsObject. By default, all users in a room that you are in can see your user variables, and receive update events when they change.


Example
This example shows how to create a user variable, update it, and capture the UserVariableUpdateEvent and trace what is going on.
     import com.electrotank.electroserver4.ElectroServer;
    import com.electrotank.electroserver4.entities.UserVariable;
    import com.electrotank.electroserver4.esobject.EsObject;
    import com.electrotank.electroserver4.message.event.UserVariableUpdateEvent;
    import com.electrotank.electroserver4.message.MessageType;
    import com.electrotank.electroserver4.message.request.UpdateUserVariableRequest;
    import com.electrotank.electroserver4.user.User;
    var es:ElectroServer;//Assume a connection was created elsewhere and you're logged in.
    function init():void {
        es.addEventListener(MessageType.UserVariableUpdateEvent, "onUserVariableUpdatedEvent", this);
    }
    function createAndUpdateUserVariable():void {
        //create the var
        var uuvr:UpdateUserVariableRequest = new UpdateUserVariableRequest();
        uuvr.setName("Test");
        var esob:EsObject = new EsObject();
        esob.setString("TestVar", "hello there");
        uuvr.setValue(esob);
        //send it
        es.send(uuvr);
        /////////////
        //update the var
        //
        uuvr = new UpdateUserVariableRequest();
        uuvr.setName("Test");
        esob = new EsObject();
        esob.setString("TestVar", "i said hello!");
        //send it
        es.send(uuvr);
    }
    function onUserVariableUpdatedEvent(e:UserVariableUpdateEvent):void {
        var u:User = e.user;
        var name:String = e.getVariableName();
        trace("User variable name: "+name);
        switch (e.getActionId()) {
            case UserVariableUpdateEvent.VariableCreated:
                var uv:UserVariable = u.getUserVariable(name);
                trace("User variable created");
                trace("User variable value: "+uv.getValue().getString("Test"));
                break;
            case UserVariableUpdateEvent.VariableUpdated:
                var uv:UserVariable = u.getUserVariable(name);
                trace("User variable updated.");
                trace("User variable value: "+uv.getValue().getString("Test"));
                break;
            case UserVariableUpdateEvent.VariableDeleted:
                trace("User variable deleted.");
                break;
            default:
                trace("Update action not handled: "+e.getActionId());
                break;
        }
    }
    init();
    createAndUpdateUserVariable();
    



Public Methods
 MethodDefined by
  
Creates a new instance of the UpdateUserVariableRequest.
UpdateUserVariableRequest
  
getName():String
Gets the name of the variable to create or udpate.
UpdateUserVariableRequest
  
Gets the value of the variable.
UpdateUserVariableRequest
  
setName(name:String):void
Sets the name of the variable to create or update.
UpdateUserVariableRequest
  
setValue(value:EsObject):void
Sets the value of the variable.
UpdateUserVariableRequest
  
UpdateUserVariableRequest
Constructor detail
UpdateUserVariableRequest()constructor
public function UpdateUserVariableRequest()

Creates a new instance of the UpdateUserVariableRequest.

Method detail
getName()method
public function getName():String

Gets the name of the variable to create or udpate.

Returns
String — The name of the variable to create or udpate.
getValue()method 
public function getValue():EsObject

Gets the value of the variable.

Returns
EsObject — The value of the variable.
setName()method 
public function setName(name:String):void

Sets the name of the variable to create or update.

Parameters
name:String — The name of the variable to create or udpate.
setValue()method 
public function setValue(value:EsObject):void

Sets the value of the variable.

Parameters
value:EsObject — The value of the variable.
validate()method 
public override function validate():ValidationResponse

Returns
ValidationResponse