PunTurnManager Help

Options
aholla
aholla
Hi I am using PunTurnManger in my game and getting an error. I was hoping someone might know what is wrong.

Here is the process:

Master calls "BeginTurn". All players receive "OnTurnBegins". When a player ends their turn, I iterate over all players to check if they have finished their turn, this is where the error occurs. If the Player is not the master i get a Null reference error on this line:

(int)room.CustomProperties[propKey];

The room does not contain the propKey... Why might that be?
/// <summary>
        /// gets the player's finished turn (from the ROOM properties)
        /// </summary>
        /// <returns>The finished turn index</returns>
        /// <param name="player">Player reference</param>
        public static int GetFinishedTurn(this Player player) {
            Room room = PhotonNetwork.CurrentRoom;
            if (room == null || room.CustomProperties == null || !room.CustomProperties.ContainsKey(TurnPropKey)) {
                return 0;
            }

            string propKey = FinishedTurnPropKey + player.ActorNumber;
            return (int)room.CustomProperties[propKey];
        }

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited February 2019
    Options
    Hi @aholla,

    Maybe initially that player never finished any turn?
    So this method should be fixed to handle such a situation.
    I'm not familiar with the TurnManager and extensions so I may be getting this wrong.
    @jeanfabre may know better
    suggestion fix for now, assuming this happens with the first turn only:
    string propKey = FinishedTurnPropKey + player.ActorNumber;
    if (!room.CustomProperties.Contains(propKey)) 
    {
        return 0;
    }
    return (int)room.CustomProperties[propKey];
  • aholla
    Options
    Yeah thats what I initially tried but then strange things started happening.

    The player that just ended their turn is the one being checked and so should be returning 1 but instead does not exist. Theres probably a lot of things that could have gone wrong.

    I trying to use the turn manager for 2 teams of players and need to check the players state to switch the active team ...
  • aholla
    aholla
    edited February 2019
    Options
    Okay I fixed my issue.

    I had to change the order of the SendMove method.

    I moved the:
    if (finished) {
                    PhotonNetwork.LocalPlayer.SetFinishedTurn(Turn);
                }
    to above the:
    byte evCode = (finished) ? EvFinalMove : EvMove;
                PhotonNetwork.RaiseEvent(evCode, moveHt, new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache }, SendOptions.SendReliable);
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    OK I see, thanks.