Changing a players custom properties?

How do I change a players custom properties?
I have a custom player property called 'Order' which keeps track of the order that the players joined in. So when a player joins the room, it will set their player's 'Order' property to the number of players in the room (including themselves). For example if a player is the second person in the room, then his order number will be assigned to '2'. Here is the code for this:

// this works fine.

private ExitGames.Client.Photon.Hashtable customPlayerProperties = new ExitGames.Client.Photon.Hashtable();

//this method is called by OnJoinedRoom()
public void playerJoinedRoom(int numOfPlayers, PhotonPlayer playerJoined) {
customPlayerProperties.Add(RoomProperties.Order, PhotonNetwork.playerList.Length);
playerJoined.SetCustomProperties(customPlayerProperties);
}

However problems arise when a player leaves. Say there are three players in a room. Their order numbers are 1,2,3 respective to when they joined in. But, if player number 2 leaves, then I will have to change the order of player '3' to '2'. I am unable to change another persons player property, can someone please help me with this? Thanks

Best Answer

Answers

  • [Deleted User]
    edited August 2015
    Why do you need that order? When player leaves, the order of numbers is still ok but some numbers may be missing.
    Did you try set properties of other players from leaving client? It should work. If not (client is disconnected already e.g.), change properties of local players in OnPhotonPlayerDisconnected.
    Or you can keep order in custom room properties. Or use player.ID as number representing order. What is he best solution depends on what you are trying to do.
  • How exactly do I change the custom player properties in OnPhotonPlayerDisconnected()? Some example code would be helpful.
  • neel11
    neel11
    edited August 2015
    Ok, I used your idea of using the player.ID to represent the order and it works, which is great, however I still want to know how to change a player's custom properties.