Room Properties not updating properly

Options
I'm trying to use the Room's custom properties to keep track of a deck of cards. The UploadRoomCards method is called every time a player makes a move, it uploads the player's list of cards to the room.
public void UploadRoomCards()
{
     Hashtable roomProps = new Hashtable
     {
          { REMAINING_CARDS, remainingCards.ToArray() },
          { PLAYING_CARDS,   playingCardStack.ToArray()  }
      };
      Debug.Log("uploading room cards...");
      PhotonNetwork.CurrentRoom.SetCustomProperties(roomProps);
}

Then, I have the OnRoomProperties callback:
public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
{
      if (PhotonNetwork.CurrentRoom.CustomProperties.TryGetValue(PLAYING_CARDS, out object _playingCards))
      {
          var arr = (Card[])_playingCards; // This is the Room properties' value
          var test = playingCardStack.Peek(); // I store the value prior to download (this is the expected value)
          playingCardStack = new Stack<Card>(arr);
          Debug.Log(playingCardStack.Peek() + " | " + test); // Values are different! They should match!
      }
}

This gets called after UploadRoomCards as expected. That means that the UploadRoomCards IS uploading the properties. However, the propertiesThatChanged does not change. As you can see, I store the value of the array before downloading and compare it to the room value. The room value is not the one that was uploaded moments ago.

But here comes the good part: When another player makes a move and the properties are updated again, I get the value that the first player set! So it always goes 1 turn 'behind'. This is really weird. I've tried uploading twice (I know it's dirty but I'm desperate) but it doesn't work.

Example: The room has a property with a value of 1. The player makes a move, UploadRoomCards gets called and I set the value of the property to 2. The callback gets called by Photon after setting the properties, so I know that they have been uploaded. But when I read the value, it says 1! Another player sets the value to 3. When I go to read the value (after getting the callback that it was uploaded), it reads 2 (value set by player 1).

Does anyone know why this is happening?

By the way, the object type shouldn't be a problem. 'Card' is a struct containing 2 ints. It is serialized using the method described in the documentation. Plus, I've set Player properties before with no issue using that object type.

Thanks in advance

Answers

  • S_Oliver
    S_Oliver ✭✭✭
    Options
    Why you dont use an RPC for this ?
  • S_Oliver wrote: »
    Why you dont use an RPC for this ?

    What are those?
    I think they are like methods callable by everyone, but I don't really understand them.
    I'm sorry, I'm new to this.
  • S_Oliver
    S_Oliver ✭✭✭
    Options

    https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent

    Yes like a method call but the method is than called on all clients on the same GameObject.

    Im wondering that you use room properties and also use structs and implemented custom serialization for this but dont know about rpc :D ok maybe you take alook at the official pun 2 tutorials.