CustomProperties values are duplicated in all players

Options
Hi, sorry for my bad English.
I'm using PUN and I face a strange behaviour with custom properties.

I have two players per room. The first is the master and the 2nd the client. When the master enter in the scene "Game" he sets his custom property and get the type "Rouge" (Red in English)....and if it is the client he gets the type "Bleu".

The first time I make them play a party. Everything works fine. Then I make them left the party and create new one by changing the person who creates the room, so the last client become the master and the last master client become the client.

When I get their type sometimes I got Blue for the master and the client, sometimes Rouge for both...But normally it's impossible because of my code


        if (PhotonNetwork.isMasterClient) //master client is the first to connect
        {
            Debug.Log("je suis dans le master");
            ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable();
            //On instancie les infos sur son profil
            infoJoueur.Add("type", "Rouge");
            infoJoueur.Add("typePlayer", "player");
            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);
            int view = profilR.GetComponent<PhotonView>().viewID;
            
            GestionInteraction gi = profilR.GetComponent<GestionInteraction>();
            gi.majInfoProfil(view,j.pseudo, victoireDefaite, panelAttenteMatchingJoueur);


        } else { //we have the 2nd player

            ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable();
            infoJoueur.Add("type", "Bleu");
            infoJoueur.Add("typePlayer", "player2");
            infoJoueur.Add("wantReplay", "Null");
            PhotonNetwork.player.name = j.pseudo;            
            infoJoueur.Add("pseudo", j.pseudo);
            PhotonNetwork.player.SetCustomProperties(infoJoueur);
           

            PhotonPlayer[] listeJoueur = PhotonNetwork.playerList;
            ExitGames.Client.Photon.Hashtable infoPlayerRouge = listeJoueur[0].customProperties;
            ExitGames.Client.Photon.Hashtable infoPlayerRouge2 = listeJoueur[1].customProperties;

            Debug.Log(infoPlayerRouge["type"].ToString() + " " + infoPlayerRouge2["type"].ToString());
            Debug.Log(infoPlayerRouge["typeJoueur"].ToString() + " " + infoPlayerRouge2["typeJoueur"].ToString());

            PhotonNetwork.room.open = false; //On ne peut plus accéder à la room
			PhotonNetwork.room.visible = false; //La room n'est plus listée parmi la liste des room du lobby
     
		}
	}
When I display in the else the attribute type of the two players I get, Rouge and Bleu, but when I get theses values somewhere in my code I have Bleu Bleu or Rouge Rouge for the two players...and I don't know how it is possible.

These values are never changed, because I use it to know who is playing....so everywhere i should have when i get my playerList customProperties, Blue and Rouge.

I tried to add another attribute, typePlayer, but I had the same issue. The first type I got player1 and player2...but when I make them leave the room then recreate new one by changing master and client I got the same issue....

Comments

  • kosted
    Options
    Please help
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2016
    Options
    Hi @kosted,

    We apologize about the delay, sometimes we miss some discussions.

    Please try changing condition
    PhotonNetwork.isMasterClient
    to
    PhotonNetwork.player.ID == 1
  • kosted
    Options
    Thanks for your replay JohnTube, but I got the same issue. In the else of the above code, when I display the custom property I get Red and Blue. When I display these custom properties somewhere in an function somewhere i got Red and Red.
  • jeanfabre
    Options
    Bonjour :)

    Ok, I think you are simply not accessing the right instance of the player when you do so.

    I would debug this with a HUD UI on top of each player showing their custom properties.

    You can also do so in the component that deal with cusotm properties and show them in the inspector. Then you'll be able to testify better if the data is right, or if it's just a mix up when accessing data in your code. Each Player instance will have its own custom properties so you'll know straight away.

    Bye,

    Jean
  • kosted
    Options
    Bonjour Jean

    I debug my code by showing in my scene the custom property and I got exactly the same issue. I used

    PhotonPlayer[] listeJoueur = PhotonNetwork.playerList; if(PhotonNetwork.playerList.Length>=2) { ExitGames.Client.Photon.Hashtable infoPlayerRouge = listeJoueur[0].customProperties; ExitGames.Client.Photon.Hashtable infoPlayerRouge2 = listeJoueur[1].customProperties; Debug.Log(infoPlayerRouge["type"].ToString() + " " + infoPlayerRouge2["type"].ToString()); ExitGames.Client.Photon.Hashtable infoPlayer = PhotonNetwork.player.customProperties; Debug.Log(infoPlayerRouge["typeJoueur"].ToString() + " " + infoPlayerRouge2["typeJoueur"].ToString()); text1.text = PhotonNetwork.playerList.Length+" -------- is master = " + PhotonNetwork.isMasterClient; text2.text = infoPlayerRouge["type"].ToString() + " " + infoPlayerRouge2["type"].ToString(); }

    to show the information i want to see. In the screen of the master client, I have
    Rouge Bleu
    and in the client I have
    Rouge Rouge
    , with the same code :/ .



    So i decided to debug ExitGames.Client.Photon.Hashtable infoPlayer = PhotonNetwork.player.customProperties; using break point in visual studio, but i got the same issue.

    here a link of a screenshot. The first time they played

    http://kosted.free.fr/1.PNG

    They leave room and replay

    I got this :

    http://kosted.free.fr/2.PNG

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

    I guess I would consider the following, you should access players by name, instead of by index in the room.

    Can you give a unique name to all your players in room, and actually always refer to players using their unique ID, as opposed as their index in the room. I think this is the problem.

    Bye,

    Jean
  • kosted
    Options
    Hi jean,
    I tried to do what you suggest but I don't know how to access my players by their name.

    for each player, I set their name to have unique name

    ExitGames.Client.Photon.Hashtable infoJoueur = new ExitGames.Client.Photon.Hashtable(); infoJoueur.Add("type", "Bleu"); infoJoueur.Add("typeJoueur", "Joueur2"); infoJoueur.Add("wantReplay", "Null"); PhotonNetwork.player.name = j.pseudo; // HERE THE NAME infoJoueur.Add("pseudo", j.pseudo); // THE SAME NAME IN THE CUSTOM PROPERTY PhotonNetwork.player.SetCustomProperties(infoJoueur);

    I don't know how to access my players by their name in my custom properties or by their unique id. I tried to replace index by name but it doesn't work...
  • jeanfabre
    Options
    Hi,

    I think I misleaded you here, you don't need to store the player.name in the player property, but instead name player "bleu" and name the other player "rouge", then you won't have any possible mix up.

    to find a player by name, you need to iterate the Player.List that's all.

    so when you detect 2 players, go trhough them and set/get properties based on their name ( "bleu" or "rouge")

    Bye,

    Jean
  • kosted
    Options
    I did what you said

    if(PhotonNetwork.playerList.Length>=2) { for (int i =0; i< PhotonNetwork.playerList.Length; i++) { Debug.Log("indice =" + i); ExitGames.Client.Photon.Hashtable infoPlayerRo = listeJoueur[i].customProperties; if(infoPlayerRo.ContainsValue("Bleu")) { Debug.Log("YEEEEEEEEEEEEEEEEEEEEEEEEEEEES"); } Debug.Log(infoPlayerRo["type"].ToString() + " " + infoPlayerRo["type"].ToString()); }

    The first time I got
    YEEEEEEEEEEEEEEEEEEEEEEEEEEEES
    in the client and master client. I stopped the party, changed the master client, I got nothing in the client .

    Finally I used a static variable to know who is playing if it is my blue player or the red...

    Maybe i should use RPC to update my custom properties... :/
  • jeanfabre
    Options
    Hi,

    You seem to indeed have a very odd issue here. I am not too sure what to suggests, indeed RPC could be safer to use in your scenario.

    Bye,

    Jean
  • kosted
    Options
    ok. A a last question please...I'm developing a party with friend. And a friend can see if others are connected or not and join them if they are connected...
    I find this asset https://assetstore.unity3d.com/en/#!/content/44316. Is this asset reliable ?

    And is it possible for my player before joining the room to get roomOptions ? because I need it to know which type of party i have to instantiate ...
  • jeanfabre
    Options
    Hi,

    For the price, it's likely a good purchase, just to get a template to work from, but I don't know the quality of this asset, as I haven't used it myself. It has not been released for a while now, so it might require a bit of fiddling around.

    What you need to do in order to view rooms properties is to explicitly expose the room properties to the lobby.

    check this thread for more info:http://forum.photonengine.com/discussion/1457/getting-roominfo-customproperties-in-lobby

    basically, when creating a room, you are going to pass the list of properties to expose in lobby:

    http://doc-api.exitgames.com/en/pun/current/class_room_options.html#a8c4bca19c674840296f924ec701b9ee1

    Bye,

    Jean

  • kosted
    Options
    Ah ok, it's just a template...I thought that with it, i'm not going to code :D .Thanks for the links, I got all answers I needed.
  • jeanfabre
    Options
    Hi,

    Sorry, I may not have been clear. It seems to be a fully working solution, I just meant that you could simply take the code as a base and modify it to your own liking.

    Bye,

    Jean
  • kosted
    Options
    Please Jean is it possible to get specific room properties in lobby. For example I want the rooms properties of my friend Marc, who is waiting for me in an hidden room.

    How could I make the request ? I know the name of my frien, and with Photon Friend List I can find him if he is connected...but how could I get his room properties, because if i understand well all room properties are in the lobby.

    Thanks in advance
  • jeanfabre
    Options
    Hi,

    Nop, not all room properties are visible in the lobby, only the one you explicitly define as visible.

    http://doc-api.exitgames.com/en/pun/current/class_room_options.html#a8c4bca19c674840296f924ec701b9ee1

    So, once you get the friendlist and that "Marc" is listed to be in a room. You can then use the room Id to find the room and check for the properties.

    If you hide the room, then you won't see it... :) so I think you have a conflict in your logic.

    instead of hidding the room, you could have a room property "hidden" and you don't list the ones with hidden set to true. then you can still query rooms in lobbies where friends might be waiting.


    Bye,

    Jean
  • kosted
    Options
    "you could have a room property "hidden"", great idea, so if i do a random matchmaking, i couldn't find this room and find it only with the id get by "find friend". Thanks a lot...I have all information to start coding.

    Encore une fois Merci
  • jeanfabre
    Options
    de rien :)

    Bonne journée,

    Jean
  • kosted
    Options
    Hi, I tried by multiple ways to use find friends but i got always offline.

    this is my workflow /:
    in my awake function players set PhotonNetwork.playerName = playerName

    when i do this code
    PhotonNetwork.FindFriends(nomAmi);
    in another player but i get always offline.

    What did I do wrong ?
  • Tobias
    Options
    You need to set a userID in the AuthValues. This identifies a client as user and then this client can be found by FindFriends (again with the userID).

    The playerName is not enough to find someone. It might be edited. The userID is supposed to be fixed.
  • kosted
    Options
    Thanks Tobias, but i got the same result. Maybe because I don't know how to use it.

    this is my awake function , i make the connection iside it
        // Use this for initialization
        void Awake()
        {
            // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
            PhotonNetwork.automaticallySyncScene = true;
            Joueur j = UtilsSauvegarde.ReadJoueur(UtilsSauvegarde.cheminsauvegardeprofil);
            pseudoJ = j.pseudo;
            AuthenticationValues ath = new AuthenticationValues();
            ath.UserId = pseudoJ;
    
            //On set le nom du joueur avant de joindre le lobby
            PhotonNetwork.playerName = j.pseudo;
    
            // the following line checks if this client was just created (and not yet online). if so, we connect
            if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
            {
                Debug.Log("i'm here");
                // Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
                PhotonNetwork.ConnectUsingSettings(GestionnairePartie._gameVersion);
            }
        }
    and to get my player i use this
        public void test()
        {
            
            string[] nomAmi = new string[1];
            nomAmi[0] = "kosted";
            PhotonNetwork.FindFriends(nomAmi);
        }
    kosted, is the first player to connect...
    what's wrong with this code ?

    Thanks
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @kosted,

    Please next time do not ask completely separate questions in a single discussion. Instead open a new discussion per question. But before that, please check if your question was not already asked/posted.

    For instance, you can find what your answer about how to use FindFriends in this disucssion.
  • kosted
    Options
    Sorry for this, and thanks for the answer, i'm going to test it
  • kosted
    Options
    Thanks a lot. It works