Why after connecting I have not created an actor?

edited February 2014 in Flash (deprecated)
Why after connecting I have not created an actor?

I am use Photon-Flash_v3-2-1-4_Cloud_SDK.
Adobe Flash CS6 . AS 3.0

MY LOG
Server : 137.116.219.181:4531
Players : 5/0
ROOM : room1
Actor Name : User1
Actor Num : 1
Actor Local : true
Actor in Room : room1


SERVER LOG
[info] LoadBalancingClient: State: Uninitialized -> ConnectingToMasterserver
[info] LoadBalancingClient: Connecting to Master app.exitgamescloud.com:4530
[info] Master: Connected
[info] Master: Authenticate...
[info] Master: Authenticated
[info] LoadBalancingClient: State: ConnectingToMasterserver -> ConnectedToMaster
[info] Master: Join Lobby Sin City undefined ...
[info] Master: Joined to Lobby
[info] LoadBalancingClient: State: ConnectedToMaster -> JoinedLobby
[info] Master: Create Room Sin City undefined ...
[info] LoadBalancingClient: Connecting to Game 137.116.219.181:4531
[info] LoadBalancingClient: State: JoinedLobby -> ConnectingToGameserver
[info] Game: Connected
[info] Game: Authenticate...
[info] Game: Authenticated
[info] Game: Connected
[info] Game: Create Room Sin City undefined ...
[info] LoadBalancingClient: State: ConnectingToGameserver -> ConnectedToGameserver
[info] Game: myActor:
[info] LoadBalancingClient: State: ConnectedToGameserver -> Joined

Comments

  • I don't see any problems in logs above. LoadBalancingClient log (you name it 'SERVER LOG' for some reason) shows standard initialization process from connection to joining the room. During this process, actor is created and put in the room.
    May be there are some clues in 'MY LOG', but I definitely need more detailed description what does it mean.
  • Maybe I do not understand?

    After creating an actor, I call a function

    var server: LoadBalancingClient;
    server.myActor (). getRoom (). playerCount

    and get 0

    why?
    Or so it should be?

    My Source

    [code2=as3]import flash.display.Sprite;
    import flash.external.ExternalInterface;

    import exitgames.photon.internals.DebugOut;
    import exitgames.photon.events.*;
    import exitgames.common.*;
    import exitgames.photon.loadbalancing.*;
    import exitgames.photon.*;


    var Fpeer:PhotonPeer;
    var server:LoadBalancingClient;
    var options:Object = new Object();
    options.keepMasterConnection = false;
    options.lobbyName = "Sin City";
    //options.lobbyType=static.Default;
    options.lobbyStats = true;
    options.isVisible = true;
    options.maxPlayers = 5;
    options.emptyRoomLiveTime = 1000;
    options.isOpen = true;
    options.keepMasterConnection = true;

    //server.myRoom().setMaxPlayers(10);
    //server.myRoom().name="room1";
    //server.createRoom("room1",options);


    function actor():void{
    server.myActor().setName(username.text);
    server.myActor().actorNr=1;
    //server.myActor().isLocal=false;
    };

    var SERVER:String = "app.exitgamescloud.com:4530";
    var APPLICATIONID:String = "aa545bfa-86e6-4cd3-b737-a0d20a55daf1";//use your own app id here
    var APPLICATIONVERSION:String = "v1.0";

    Fpeer = new PhotonPeer("RX");
    server = new LoadBalancingClient(SERVER,APPLICATIONID,APPLICATIONVERSION);
    server.connect(options);



    function TEST():void{

    traccer.text="";

    traccer.appendText("Server : "+server.myRoom().address+'\n');
    traccer.appendText("Players : "+server.myActor().getRoom().maxPlayers+"/"+server.myActor().getRoom().playerCount+'\n');
    traccer.appendText("ROOM : "+server.myActor().getRoom().name+'\n');
    traccer.appendText("Actor Name : "+server.myActor().name+'\n');
    traccer.appendText("Actor Num : "+server.myActor().actorNr+'\n');
    traccer.appendText("Actor Local : "+server.myActor().isLocal+'\n');
    traccer.appendText("Actor in Room : "+server.myActor().getRoom().name+'\n');

    if(server.isJoinedToRoom()){
    traccer.appendText("isJoined "+'\n');
    };


    setTimeout(TEST,1000);
    }
    setTimeout(TEST,1000);
    //////////////////////////////////////

    CreateAndJoin.addEventListener(MouseEvent.CLICK, rx_CreateAndJoin);

    function rx_CreateAndJoin(event:MouseEvent):void
    {

    if(server.isInLobby()){
    actor();
    server.createRoom("room1",options);

    var D:Actor = new Actor("RX",1,false);

    };


    }

    ///////////////////////////////////////////////////

    Join.addEventListener(MouseEvent.CLICK, rx_Join);

    function rx_Join(event:MouseEvent):void
    {
    if(server.isInLobby()){
    actor();
    server.joinRoom("room1",options);
    }
    }

    //////////////////

    Disconnect.addEventListener(MouseEvent.CLICK, RX_Disconnect);

    function RX_Disconnect(event:MouseEvent):void
    {
    server.leaveRoom();
    }[/code2]

    What do I need to do next that would create an actor in the room?
    And how to attach event listeners to nimu?
    And how to read the event?
  • 1. myActor().getRoom() can be replaced with myRoom()
    2. myRoom().playerCount property does not work for joined room currently, count myRoomActors() elements instead:
    [code2=as3]var count:int = 0;
    for (var p: * in myRoomActors() ) {
    ++count;
    }[/code2]
    playerCount is intended to be used with rooms from availableRooms() list which returns properties of rooms currently available for joining. I agree that it's useful for joined room too, so you can treat this as a bug.
    3. Did you check 'demo-loadbalancing' sample from Photon flash SDK? Does it work for you? It has all basic operations that you need.
  • Thanks for the help

    Yes, I checked the 'demo-loadbalantsing

    Everything works fine in Flash Develop

    But all this can not run in Adobe Flash CS6

    Nemog if you show a very simple example Send a message and receive a message?
  • [code2=as3]import flash.display.Sprite;
    import flash.external.ExternalInterface;

    import exitgames.photon.internals.DebugOut;
    import exitgames.photon.events.*;
    import exitgames.common.*;
    import exitgames.photon.loadbalancing.*;
    import exitgames.photon.*;


    var Fpeer:PhotonPeer;
    var server:LoadBalancingClient;
    var options:Object = new Object();
    options.keepMasterConnection = false;
    options.lobbyName = "Sin City";
    //options.lobbyType=static.Default;
    options.lobbyStats = true;
    options.isVisible = true;
    options.maxPlayers = 5;
    options.emptyRoomLiveTime = 1000;
    options.isOpen = true;
    options.keepMasterConnection = true;

    //server.myRoom().setMaxPlayers(10);
    //server.myRoom().name="room1";
    //server.createRoom("room1",options);


    function actor():void{
    server.myActor().setName(username.text);
    server.myActor().actorNr=1;
    //server.myActor().isLocal=false;
    };

    var SERVER:String = "app.exitgamescloud.com:4530";
    var APPLICATIONID:String = "aa545bfa-86e6-4cd3-b737-a0d20a55daf1";//use your own app id here
    var APPLICATIONVERSION:String = "v1.0";

    Fpeer = new PhotonPeer("RX");
    server = new LoadBalancingClient(SERVER,APPLICATIONID,APPLICATIONVERSION);
    server.connect(options);

    var count:int = 0;

    function TEST():void{

    if(server.availableRooms().length>0){
    trace(server.availableRooms()[0].playerCount);
    }

    count= 0;
    for (var p: * in server.myRoomActors() ) {
    ++count;
    }

    traccer.text="";

    traccer.appendText("Server : "+server.myRoom().address+'\n');
    traccer.appendText("Players : "+server.myActor().getRoom().maxPlayers+"/"+count+'\n');
    traccer.appendText("ROOM : "+server.myActor().getRoom().name+'\n');
    traccer.appendText("Actor Name : "+server.myActor().name+'\n');
    traccer.appendText("Actor Num : "+server.myActor().actorNr+'\n');
    traccer.appendText("Actor Local : "+server.myActor().isLocal+'\n');
    traccer.appendText("Actor in Room : "+server.myActor().getRoom().name+'\n');
    traccer.appendText('\n'+"//...Get Rooms List < Name : MaxPlayer/PlayerCount > "+'\n');

    for (var ps: * in server.availableRooms() ) {
    traccer.appendText(server.availableRooms()[ps].name+" : "+server.availableRooms()[ps].maxPlayers+"/"+server.availableRooms()[ps].playerCount+'\n');
    }



    if(server.isJoinedToRoom()){
    //traccer.appendText("isJoined "+'\n');
    };


    setTimeout(TEST,1000);
    }
    setTimeout(TEST,1000);
    //////////////////////////////////////

    CreateAndJoin.addEventListener(MouseEvent.CLICK, rx_CreateAndJoin);

    function rx_CreateAndJoin(event:MouseEvent):void
    {

    if(server.isInLobby()){
    actor();
    server.createRoom("room1",options);

    var D:Actor = new Actor("RX",1,false);

    };


    }

    ///////////////////////////////////////////////////

    Join.addEventListener(MouseEvent.CLICK, rx_Join);

    function rx_Join(event:MouseEvent):void
    {
    if(server.isInLobby()){
    actor();
    server.joinRoom("room1",options);
    }
    }

    //////////////////

    Disconnect.addEventListener(MouseEvent.CLICK, RX_Disconnect);

    function RX_Disconnect(event:MouseEvent):void
    {
    server.leaveRoom();
    }[/code2]

    Understand how to get a list of rooms and get the name of the room. MaxPlayer. PlayerCount

    How to get players to join the event room?

    I used

    if (server.isJoinedToRoom ()) {
    traccer.appendText ("isJoined" + '\ n');
    };

    know that I was connected to the room.

    And how do you know when others are connected?

    How to send and receive events?

    Help me understand the events !!!
  • Standard approach is extending LoadBalancingClient and override handlers to react on events and client state change.
    Please check essentials from demo-loadbalancing code below. It would not compile but will give you general idea and can be starting point for your app.
    [code2=as3]public class DemoChat extends LoadBalancingClient
    {
    public function DemoChat(sprite:DemoChatSprite)
    {
    super(serverAddress, appId, appVersion);
    myActor().setName("Actor_" + Math.ceil(Math.random() * 1000));
    connect(); // connect to master server
    }

    override protected function onError(errorCode:int, errorMsg:String):void
    {
    trace("Error", "Load Balancing Client Error", errorCode, errorMsg);
    }

    override protected function onStateChange(state:int):void
    {
    trace("State changed to ", state);
    switch (state)
    {
    case LoadBalancingClient.State.JoinedLobby:
    // choose game from availableRooms() (joinRoom(...)) or create room (createRoom(...)) here
    break;
    case LoadBalancingClient.State.Joined:
    trace("Joined room " + myRoom().name + " on " + server + ", app " + appId + " v" + appVersion);
    // start play here
    break;
    case LoadBalancingClient.State.Disconnected:
    connect(); // connecting back to master server or other action of your choice on disconnect
    break;
    }
    }

    override protected function onActorJoin(actor:Actor):void
    {
    // handle new player joined to your room
    }

    override protected function onActorLeave(actor:Actor):void
    {
    // handle player left your room
    }

    override protected function onEvent(code:int, content:Object, actorNr:int):void
    {
    // incoming events
    switch (code)
    {
    case GameConstants.EvChat:
    if (myRoomActors()[actorNr])
    {
    trace("Message received from ", content["senderName"], ": ", content["message"]);
    }
    break;
    default:
    break;
    }
    }

    public function sendMessage(msg:String):void
    {
    // outgoing events
    var data:Object = new Object;
    data["message"] = msg + myRoom().playerCount;
    data["senderName"] = myActor().name;
    raiseEvent(GameConstants.EvChat, data);
    }
    }[/code2]
  • Many thanks! )))
    I could run it!
    Everything works fine! )))

    [code2=as3]package {

    import exitgames.photon.loadbalancing.*;
    import exitgames.photon.demo.*;
    import exitgames.photon.constants.Constants;


    public class DemoChat extends LoadBalancingClient
    {

    var GameConstants:int=0;


    var server:String = "app.exitgamescloud.com:4530";
    var appId:String = "aa545bfa-86e6-4cd3-b737-a0d20a55daf1";//use your own app id here
    var appVersion:String = "v1.0";

    public function DemoChat()
    {
    super(server, appId, appVersion);
    myActor().setName("Actor_" + Math.ceil(Math.random() * 1000));
    connect(); // connect to master server
    }

    override protected function onError(errorCode:int, errorMsg:String):void
    {
    trace("Error", "Load Balancing Client Error", errorCode, errorMsg);
    }

    override protected function onStateChange(state:int):void
    {
    trace("State changed to ", state);
    switch (state)
    {
    case LoadBalancingClient.State.JoinedLobby:
    // choose game from availableRooms() (joinRoom(...)) or create room (createRoom(...)) here
    trace("Можно создать комнату");
    break;
    case LoadBalancingClient.State.Joined:
    trace("Joined room " + myRoom().name + " on " + server + ", app " + appId + " v" + appVersion);
    // start play here
    break;
    case LoadBalancingClient.State.Disconnected:
    connect(); // connecting back to master server or other action of your choice on disconnect
    break;
    }
    }

    //..My Function
    public function JoinRoom(Name:String,Options:Object):void{

    joinRoom(Name,Options);
    }
    //..

    override protected function onActorJoin(actor:Actor):void
    {
    // handle new player joined to your room
    trace("Кто то подключился");
    }

    override protected function onActorLeave(actor:Actor):void
    {
    // handle player left your room
    trace("Кто то отключился");
    }

    override protected function onEvent(code:int, content:Object, actorNr:int):void
    {
    // incoming events
    switch (code)
    {
    case GameConstants:
    if (myRoomActors()[actorNr])
    {
    trace("Message received from ", content["senderName"], ": ", content["message"]);
    }
    break;
    default:
    break;
    }
    }

    public function sendMessage(msg:String):void
    {
    // outgoing events
    var data:Object = new Object;
    data["message"] = msg + myRoom().playerCount;
    data["senderName"] = myActor().name;
    raiseEvent(GameConstants, data);
    trace("сообщение отправлено"+msg);
    }
    }


    }[/code2]
  • Dear Radmir,
    According to your code, I can connect to GameServer . In next, would you like to help me a example to send and receive message after creating and joining my room. (you can give me skype name to discuss some problem of Flash client)

    And this trace from Flash develop:

    [info] LoadBalancingClient: State: Uninitialized -> ConnectingToMasterserver
    [info] LoadBalancingClient: Connecting to Master app.exitgamescloud.com:4530
    [info] Master: Connected
    [info] Master: Authenticate...
    [info] Master: Authenticated
    [info] LoadBalancingClient: State: ConnectingToMasterserver -> ConnectedToMaster
    [info] Master: Join Lobby Sin City undefined ...
    [info] Master: Joined to Lobby
    [info] LoadBalancingClient: State: ConnectedToMaster -> JoinedLobby
    aaaaaaaaaa
    [info] Master: Create Room Sin City undefined ...
    Server :
    Players : 5 / 1
    ROOM : room1
    Actor Name : tuan anh
    Actor Num : 1
    Actor Local : true
    Actor in Room : room1
    [info] LoadBalancingClient: Connecting to Game 85.17.196.159:4531
    [info] LoadBalancingClient: State: JoinedLobby -> ConnectingToGameserver
    [info] Game: Connected
    [info] Game: Authenticate...
    [info] Game: Authenticated
    [info] Game: Connected
    [info] Game: Create Room Sin City undefined ...
    [info] LoadBalancingClient: State: ConnectingToGameserver -> ConnectedToGameserver
    [info] Game: myActor:
    [info] LoadBalancingClient: State: ConnectedToGameserver -> Joined
Sign In or Register to comment.