Getting player custom props
Options
egress
✭
Hi guys, been working with Photon Turnbased 4.0.0.4 and I've run into this problem. Not sure if I'm doing it the wrong way but some input would be great.
I'm trying to get a list of player custom properties in a room (their in-game name, specifically).
In OnEvent, I then listen for EventCode.Join and EventCode.Leave, which calls a function on the UI to update the list of players in the room.
I can't seem to access the custom properties hashtable. Any advice?
I'm trying to get a list of player custom properties in a room (their in-game name, specifically).
Hashtable customProps = new Hashtable(); customProps.Add ("n", playerName); // client refers to a subclassed LoadBalancingClient client.LocalPlayer.SetCustomProperties (customProps);
In OnEvent, I then listen for EventCode.Join and EventCode.Leave, which calls a function on the UI to update the list of players in the room.
for (int i = 0; i < client.CurrentRoom.PlayerCount; i++) { // Here client.CurrentRoom.PlayerCount returns the correct number Hashtable customProps = client.CurrentRoom.Players[i].CustomProperties; // However this gives a KeyNotFoundException }
I can't seem to access the custom properties hashtable. Any advice?
0
Comments
-
I guess it's a simple timing issue.
If you set the custom property after a player joined a room, then the info won't be available in the join-event on the other clients.
You can set local player properties before you call join/create. This way, the property is available when you enter the room and when the others get the join event.
Leave will first remove the player from the list (and the properties of this player, too) and then execute the callback. In this case it would be much easier if your code would run first and then call base.OnEvent().
Let me know if this makes sense to you or if there are further problems with this approach. Maybe I am on a wrong track and should modify Turnbased for this case.
So, we are open for feedback on this.0 -
I have discovered that the error was caused by a silly misunderstanding on my part.
I was using a for loop (starting at 0) to access the CurrentRoom.Players dictionary, but the key starts at 1 and not 0. I have since switched to using foreach to loop through the dictionary.
Thanks for taking a look, though I'm sure I will have more questions forthcoming as I explore the SDK.0 -
Good you could find it! Thanks for the update.0