Hashtable Sync issue (pun2) Please help me ;)
Options
the problem i have is highlighted in italic:
am i right in saying each player has an individual player.customperperties and that i can access there saved values though the Player in the playerlist? (please shed some light/ help) thank you so much.
(//Called on a scene object that every player has in their scene. )
declaring hashtables as photonhash:
the defined hashtable:
in my Start() method:
am i right in saying each player has an individual player.customperperties and that i can access there saved values though the Player in the playerlist? (please shed some light/ help) thank you so much.
(//Called on a scene object that every player has in their scene. )
declaring hashtables as photonhash:
using Hashtable = ExitGames.Client.Photon.Hashtable;
the defined hashtable:
Hashtable CustomHash = new ExitGames.Client.Photon.Hashtable();
in my Start() method:
CustomHash.Add("Red",0); CustomHash.Add("Blue",0); CustomHash.Add("Ready",0); PhotonNetwork.LocalPlayer.SetCustomProperties(CustomHash); PhotonNetwork.LocalPlayer.CustomProperties = CustomHash; checkteams(); // used after checking teams to assign the player to the team with least players if(Blue <= red) { TeamSelection(1); } if(red < Blue) { TeamSelection(2); }
public void CheckTeams() { if (!GameStarted) { red = 0; Blue = 0; PlayersReady = 0; BluePlayers_Text.text = ""; RedPlayers_Text.text = ""; foreach (Player player in PhotonNetwork.PlayerList) { [i]Hashtable h = player.CustomProperties; <--------------------------------------------- //values are not being fetched here or there not being set in start on the clients. string s = ""; int R = (int)h["Red"]; int B = (int)h["Blue"]; int ready = (int)h["Ready"];[/i] if (R == 1) { red++; if (ready == 0) { s = ""; } else if (ready == 1) { PlayersReady++; s = " (Ready)"; } RedPlayers_Text.text = RedPlayers_Text.text.ToString() + player.NickName.ToString() + s.ToString() + "\n"; return; } if (B == 1) { Blue++; if (ready == 0) { s = ""; } else if (ready == 1) { PlayersReady++; s = " (Ready)"; } BluePlayers_Text.text = BluePlayers_Text.text.ToString() + player.NickName.ToString() + s.ToString() + "\n"; return; } } } }
0
Comments
-
i forgot to mention the host data is sent to clients0
-
Hi, check out my team implementation, its quite simple.
https://github.com/SradnickDev/Photon-Misc/tree/master/Assets/TeamsIm using a array to store teams.
e.g.
An int array of size of 2 means 2 Teams where each index is the amount of players in a team [0]=2 (team 1 has 2 players). This array is stored as a room property and a player stores just the index of the team he belongs to ,as player property.1 -
i get what you did and how you implemented but how does the player.customproperties set are they individual to each player?0
-
Yes each you can set the properties to each player, so each player has its own properties.
To simplify reading/writing propeties i've written a wrapper https://github.com/SradnickDev/Photon-Misc/blob/master/Assets/Utilities/PropertyHelper.cs.
On top of this i usually pot methods that do exactly what i want
https://github.com/SradnickDev/Photon-Misc/blob/master/Assets/Utilities/PlayerExt.cs
with this you can access player properties like thisPhotonNetwork.LocalPlayer.SetScore(10); or var scoreFromPlayerX = photonView.OwnerGetScore();
You just have to write these extra layer once and your code looks alot cleaner an its easier to change or debug.0