PhotonPlayer.SetCustomProperties (or get?) weird behavior

Options
Hello,
Trying to make a card game, the masterclient shuffles a deck and then setting each player's deck by setting the custom properties.

This is the general flow\code:
using Hashtable = ExitGames.Client.Photon.Hashtable;

public classGameManager : PunBehaviour
{
    private PhotonPlayer local;
    Hashtable player0pht;

    public override void OnJoinedRoom()
    {
            local = PhotonNetwork.player;
            if (PhotonNetwork.isMasterClient)
            {
                     player0pht = new Hashtable();
                     for (int i = 0; i < entireDeck.Count; i++) // entireDeck = list of cards
                     {
                                 // local player will only get any second card of the deck
                                  if (i % 2 == 0)
                                 { player0pht.Add(i / 2, entireDeck[i]); 
                     }
                     local.SetCustomProperties(player0pht);
                     player0pht.PrintHashtable(); // Print A (extension method to print the hashtable)
                     print("local properties count: " + local.CustomProperties.Count);
                     local.CustomProperties.PrintHashtable(); // Print B
            }
    }
}
Print A is fine.
Print B is empty (no hashtable). (and the line before is "local properties count: 0")
what's wrong in this picture?

Comments

  • OEis
    Options
    I'll answer my own question :)
    there were two problems here, and the solution is the same for both: convert both the key and value to string.
    - the key of the hashtable must be a string
    - the value needs to be "basic" type, e.g. string, int etc. (it doesn't help that the value is defiend as Serializable, photon can't read it. the simple solution is to override ToString)

    so the add line should be:
    player0pht.Add((i / 2).ToString(), entireDeck[i].ToString());
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @OEis,

    Thank you for choosing Photon!

    Please read more about Photon serialization supported types and custom type serialization here.