Restart two scenes in a room and keep the room closed

Options
Hi All,
first of all sorry for my bad Englsih, i'm going to try to be clear.

I'm making a board game and there are two players in a room. When the first player (Player 1) is connected, he loads his scene and waits for an opponent. When a second player (Player 2) connects, he loads another scene. So we have two scenes in a room, but only holes and panws of the board game are sync between the two players. At that moment, I close the room.

At the end of the game when, they want to restart, I send RPC, and they restart...but I have an issue. When they restart, for example, I have a player (player 3) waiting for an oppenent, this player is going to play with player 1 or player 2, if it is player 1 who restarts first or not.

So I think that when they restart, the room is re-open. How can I keep the room closed ?

my short code

    [PunRPC]
    public void PreparartionRestart(int view)
    {
        GameObject gameManager = PhotonView.Find(view).gameObject;
        Text textD = GameObject.Find("TextDebug").GetComponent<Text>();
        textD.text = "back in the client ";
        Debug.Log("in the method");

        gameManager.GetComponent<PhotonView>().RPC("PreparartionRestart", PhotonTargets.OthersBuffered, new object[] { view });
        SceneManager.LoadSceneAsync("Jeu");
    }

Comments

  • jeanfabre
    Options
    Bonjour :)

    Have you worked with Open and Visible properties of rooms?

    http://forum.photonengine.com/discussion/4119/close-room-even-if-others-are-in-it

    Bye,

    Jean




  • kosted
    Options
    jeanfabre said:

    Bonjour :)

    Have you worked with Open and Visible properties of rooms?

    http://forum.photonengine.com/discussion/4119/close-room-even-if-others-are-in-it

    Bye,

    Jean




    Thanks for your answer. Yes, just after the connection of the 2nd player I close the room by setting visible to false. But when I restart it seems that room re-opens
  • jeanfabre
    Options
    Hi,

    visibility isn't affecting the "close" state of a room, you need to close it as well, is that the case?

    Bye,

    Jean
  • kosted
    Options
    jeanfabre said:

    Hi,

    visibility isn't affecting the "close" state of a room, you need to close it as well, is that the case?

    Bye,

    Jean

    this the code I use when I close the room
    PhotonNetwork.room.open = false; 
    PhotonNetwork.room.visible = false;
  • jeanfabre
    Options
    Ok,

    Are you positive you are joining the room you've closed? I think what could happen is that a player from a room can join it if closed. I'll ask for a confirmation of this.

    Maybe you could rephrase the problem, I am trying to make sense of your explanation but I am still unsure about what you are experiencing. I am also not a native english speaker .)

    Bye,

    Jean
  • kosted
    Options
    jeanfabre said:

    Ok,

    Are you positive you are joining the room you've closed? I think what could happen is that a player from a room can join it if closed. I'll ask for a confirmation of this.

    Maybe you could rephrase the problem, I am trying to make sense of your explanation but I am still unsure about what you are experiencing. I am also not a native english speaker .)

    Bye,

    Jean

    :) I understand well know, but I thought that when players are in the room, they can restart the game without leaving the room...In that case, it is impossible to keep players in the room when they restart, because room are closed :/ ! but if I don't close the room, everybody can join it and I can have more than 2 players in the room :/ !
  • Tobias
    Options
    Closing a room only means that nobody can join it anymore.
    If you "restart" a match, you can keep the players in the same room. Photon does not mind what your game logic does and means. Send a RPC to restart and just play another game. No matchmaking is needed and nobody joins accidentally.
  • jeanfabre
    Options
    Hi,

    For this, you'll need to increase the Player time to Live in the RoomOptions when you create a room ( Class roomOptions() )

    PlayerTtl is in milliseconds.
    
    PhotonNetwork.CreateRoom(null, new RoomOptions() {  PlayerTtl = 600000 }, null);
    so increase this value and see if that helps you achieve the desired behaviour.

    Bye,

    Jean
  • kosted
    Options
    ok thanks, I'm gonna try it.
  • kosted
    kosted
    edited May 2016
    Options
    I got the same issue.

    First I remove the code
    PhotonNetwork.room.open = false

    And I retried. Two players (player 1 and 2) in a room and a player 3 waiting for an opponent. I send RPC to "restart" and they "restart", but the payer 3 who was waiting matches with player 1 (sometimes with player 2 when it's player 2 who restarts first), and the the player 2, at his turn starts to wait for an opponent while i wanted player 1 to play against player 2.

    I tried tu use PhotonNetwork.LoadLevel("Jeu");...but only master client restarts, client is not affected. Of course, I set automaticallySyncScene to true in the Start function.

    My game logic is
    //Callback lorsqu'on rentre dans une room (master client et client)
    	void OnJoinedRoom() {
            
            //Intanciation of holes in the board game
            instantiateTrou();
            ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable();
            //I get stats of the player, number of victories and defeats
            Joueur j = UtilsSauvegarde.ReadJoueur(UtilsSauvegarde.cheminsauvegardeprofil);
            string victoireDefaite = "Victories : " + j.victoire + " | Defeats : " + j.defaite;
    
    
            if (PhotonNetwork.room.playerCount == 1) //The first player == master client
            {
                //Information about the player
                infoJoueur.Add("type", "Rouge");
                infoJoueur.Add("wantReplay", "Null");
                PhotonNetwork.player.name = j.pseudo;          
                infoJoueur.Add("pseudo", j.pseudo);
                PhotonNetwork.player.SetCustomProperties(infoJoueur);
    
                GameObject profilR = PhotonNetwork.Instantiate(prefabProfilRouge.name, pivotRouge.transform.localPosition, Quaternion.identity, 0);
                DontDestroyOnLoad(profilR);
                int view = profilR.GetComponent<PhotonView>().viewID;
                
                GestionInteraction gi = profilR.GetComponent<GestionInteraction>();
                gi.majInfoProfil(view,j.pseudo, victoireDefaite);
    
                isRoomCreated = true;
    
            } else if(PhotonNetwork.room.playerCount == 2) { //The 2nd player
                
                //Information about the 2nd player
                infoJoueur.Add("type", "Bleu");
                infoJoueur.Add("wantReplay", "Null");
                PhotonNetwork.player.name = j.pseudo;            
                infoJoueur.Add("pseudo", j.pseudo);
                PhotonNetwork.player.SetCustomProperties(infoJoueur);
    
                //PhotonNetwork.room.open = false; //On ne peut plus accéder à la room
    			PhotonNetwork.room.visible = false; //The room is not listed in the lobby
    
                //At that moment the two players are in the room 
                GameObject profilB = PhotonNetwork.Instantiate(prefabProfilBlue.name, pivotBlue.transform.localPosition, Quaternion.identity, 0);
              
                int view = profilB.GetComponent<PhotonView>().viewID;
                GestionInteraction gi = profilB.GetComponent<GestionInteraction>();
                gi.majInfoProfil(view, j.pseudo, victoireDefaite);
                isRoomCreated = true; //le 2e joueur a rejoint une room qui existe
                //The 2nd player set the name of the two players in the label of name
                gi.afficherPseudoSurLabel(view);
                StartCoroutine(DesactiverProfilBleu(5f));           
    		}
    	}
    And the RPC for the restart is just:smile:
    
        [PunRPC]
        public void PreparationRestart(int view)
        {
            GameObject gameManager = PhotonView.Find(view).gameObject;
            Text textD = GameObject.Find("TextDebug").GetComponent<Text>();
            textD.text = "back in the client ";
            Debug.Log("in the method");
    
            gameManager.GetComponent<PhotonView>().RPC("PreparationRestart", PhotonTargets.OthersBuffered, new object[] { view });
            SceneManager.LoadSceneAsync("Jeu");
        }
    

    I don't know what should I do.
  • jeanfabre
    Options
    Hi,

    Your line is commented where you close the room.

    A closed room should a player that left to reenter if the player time to live timeout hasn't passed.

    Bye,

    Jean
  • kosted
    Options
    jeanfabre said:

    Hi,
    A closed room should a player that left to reenter if the player time to live timeout hasn't passed.

    Sorry but i didn't understand well the 2nd sentence. If I understand well, when I set TTL as you mentionned, even if the room is closed and the TTL hasn't passed they could re enter in the room ? ok, i'm gonna try it.

    Thanks
  • jeanfabre
    Options
    Hi,

    yes, the room will persists as long as players ttl that left hasn't passed ( so they could rejoin in case the lost connection for example, typically)

    Bye,

    Jean
  • kosted
    kosted
    edited May 2016
    Options
    It's weird, I don't have playerTTL in my RoomOptions. On the API doc of PUN I found this playerTTL, but in my code it is not detected. So a question, maybe playerTTL is available for specific API ? Because I red that thre is an API for turnbased game and one for others games
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Which PUN version do you use? RoomOptions.PlayerTtl was added in v1.67.
  • jeanfabre
    Options
    Hi,

    PlayerTtL is available in the regular PUN asset on the Asset store.

    I can do this and it works on the current PUN

    PhotonNetwork.CreateRoom(null, new RoomOptions() { maxPlayers = maxPlayersPerRoom, PlayerTtl = 10 }, null);

    how are you trying to access PlayerTtl?

    Bye,

    Jean
  • kosted
    kosted
    edited May 2016
    Options
    JohnTube said:

    Which PUN version do you use? RoomOptions.PlayerTtl was added in v1.67.

    Oooook, I used Photon v1.66 according to the documentation ! I'm going to update it
  • kosted
    kosted
    edited May 2016
    Options
    This bug is going to kill me :(

    After updating, I tried to set the TTL but I have the same issue. The two players leaves the room when I restart my scene.

    Then I tried another approach, when I restart my scene, I check player SetCustomProperties. If it's null, the player can try to join a random room or create a new one, if not the player is still in the room, so he don't try to join random room. But when I instantiate an object i got this error Failed to Instantiate prefab. Client should be in a room., that is to say that my players leaves the room when I restart.

    I decided to use PhotonNetwork.Loadlevel, but when I'm in the scene "Game" and I restart this scene with this PhotonNetwork.Loadlevel, only the master client is affected, but when I launch the scene "Main menu", the two players are affected, and they launched the new scene. I don't know why ?

    :'(
  • jeanfabre
    Options
    Hi,

    This looks to me that you have a explicit behaviour in your game that make the user leave the room, and you are not aware of this.

    you need to use PhotonNetwork.LoadLevel only on the masterClient, Photon will spread the word to other instances if you have automaticallySyncScene set to true. Can you double check that? as I look in the scripts you pasted, it's not the case at all.

    also, it's right that if you have left a room you can not instantiate a player, you must be in the room first, then you can instantiate your player.

    Have you wrote all the scripts used in these scenes or are you using pre made scripts shipped with Photon? if you do, you could experience some issues because you are not fully aware of all them components do by default which could get in the way of what you want to achieve.

    Usually, when I get lost to the point where it doesn't make sense anymore ( it happens often... so don't worry, we are all in the same boat :) ) I start from scratch an empty project and build the very minimal code to achieve the desire behaviour that doesn't work on that project, once I totally have it working, I have then a frame of reference to analyze back the project that doesn't work.

    So here, this would be what I would do, this will recap on the concepts and routines in their most basic forms. you just need two dummy scenes, a very crude player prefab with the bear minimum, etc and then it that is still not working, we have a solid base to analyze how to make it work.

    Bye,

    Jean
  • kosted
    Options
    I did as you recommend. I made a new project to test the behaviour and I notice two things .:

    - Player don't leaves the room as you said before. I show the room's name on the debug and when I restart, the name is still the same.
    - When I restart using Loadlvel on the master client the client restarts too, but it works just one time, if I want to restart again nothing happened.

    I put my little demo (just 2 scenes, one script) in my web site in case, in case you want to try it masseka-game-studio.com/TestPun.rar
  • jeanfabre
    Options
    Hi,

    Replied on the mail channel of this topic.

    bye,

    Jean