Cannot check if all players are ready with CustomProperties

Options
Hey folks,

I am trying to set up my game in such a way that once both players choose their race, then the game starts.

What I do is I first declare hashtable, bool and int locally:

public bool chosenRace = false; Hashtable playerCustomSettings = new Hashtable (); public int playersReady = 0;

Then in the start function I do:

void Start () { playerCustomSettings.Add ("Ready", chosenRace); playerCustomSettings.Add ("Done", false); PhotonNetwork.player.SetCustomProperties (playerCustomSettings); }

Then I have a function that is triggered when a UI button is clicked and it does the following:

public void ChooseHuman () { humanRace = true; chosenRace = true; playerCustomSettings ["Ready"] = true; PhotonNetwork.player.SetCustomProperties (playerCustomSettings); chooseRaceCanvas.enabled = false; }

and then in Update() I check:

void Update () { //if (playersReady < 2) { foreach (PhotonPlayer player in PhotonNetwork.playerList) { if ((bool)PhotonNetwork.player.CustomProperties ["Ready"] == true && (bool)PhotonNetwork.player.CustomProperties ["Done"] == false) { playerCustomSettings ["Done"] = true; playersReady = playersReady + 1; PhotonNetwork.player.SetCustomProperties (playerCustomSettings); Debug.Log (player + " " +playerCustomSettings); Debug.Log (PhotonNetwork.playerList.Length); } } //} }

What I am expecting here is: once a player chooses his race, it sets the 'Ready' key value to true. then in the update if it has not been 'Done' before, it will set it to true and will add 1 to playersReady and then will set the custom properties so this update code is not run again for this specific player. It should run only once per player if READY is true and has not been DONE before.

However, the code executes only once like it does not recognize there are TWO players in playerList and it debugs only once the player and playerCustomSettings...

I tried to Debug Log(player) after foreach function and it perfectly logs the two players. But it does execute the Update code only for the local player. It does not DEBUG LOG the name and the customsettings for the second player.


P.S. Sorry for the 'one-line' code snippets but it seems I cannot make new lines even with the HTML
! Apologies

Any ideas how I can implement this?

Comments

  • HeadlessFly
    Options
    I came up with a solution that will do it for now - one that does produce the same result but in a different way.

    I just wrote an if statement that:

    if (!done && (bool)PhotonNetwork.playerList [0].CustomProperties ["Ready"] == true && (bool)PhotonNetwork.playerList [1].CustomProperties ["Ready"] == true) { playersReady = 2; done = true; }

    You can close/delete the post, mods! :#