Strange behavior with if statement inside foreach
I want to have a score board (for now it's only showing pings but whatever) that player can look when they want. Here's my initial code :
IEnumerator MAJTableauScore ()
{
while(Input.GetButton("Score"))
{
playerlist.text = "";
foreach(PhotonPlayer playR in PhotonNetwork.playerList){
playerlist.text += playR.name + " : " + playR.customProperties["Ping"] + joueur.customProperties["Team"] + "\n";
}
yield return new WaitForSeconds(4f);
}
}
It's working fine, it shows the correct team for each player.
Now I want to add have my list like this :
Team 1:
*list of the players in team 1*
Team 2
*list of the players in team 2*
So I do this :
while(Input.GetButton("Score"))
{
photonView.RPC ("updatePing", PhotonTargets.AllViaServer);
playerlist.text = "";
playerlist.text += "Team 1" + "\n";
foreach(PhotonPlayer playRin PhotonNetwork.playerList){
if (playR.customProperties["Team"] == "team1") playerlist.text += playR.name + " : " + playR.customProperties["Ping"] + "\n";
}
playerlist.text += "\n" + "Team 2" + "\n";
foreach(PhotonPlayer playRin PhotonNetwork.playerList){
if (playR.customProperties["Team"] == "team2") playerlist.text += playR.name + " : " + playR.customProperties["Ping"] + "\n";}
yield return new WaitForSeconds(4f);
}
Now it doesn't work anymore, it only shows the player running the code.
I would guess that your customProperties["Equipe"] doesn't contain the values $$anonymous$$m1 or $$anonymous$$m2. Why does your first example use customProperties["Team"]?
Woops, little mistake, I translated the var names from French to English when copying it here so it's more clear. I'm going to change it. But no, the problem is not co$$anonymous$$g from here, on the first example it's working fine, the "playR.customProperties["Team"]" is changed to "$$anonymous$$m1" or "$$anonymous$$m2".
If you tell me the code should be working, then I guess it's another strange thing related to photon, but I hope not.
Answer by Sylvine · Sep 17, 2015 at 01:43 PM
Ok, I've got my answer. The code was fine, the problem was related to photon.
More info here : http://answers.unity3d.com/questions/1067246/rpc-target-mismatch.html#answer-form