Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     public PhotonPlayer GetNextFor(int currentPlayerId)
     {
         if (PhotonNetwork.networkingPeer == null || PhotonNetwork.networkingPeer.mActors == null || PhotonNetwork.networkingPeer.mActors.Count < 2)
         {
             return null;
         }

         Dictionary players = PhotonNetwork.networkingPeer.mActors;
         int nextHigherId = int.MaxValue; // we look for the next higher ID
         int lowestId = currentPlayerId; // if we are the player with the highest ID, there is no higher and we return to the lowest player's id

         foreach (int playerid in players.Keys)
         {
             if (playerid < lowestId)
             {
                 lowestId = playerid; // less than any other ID (which must be at least less than this player's id).
             }
             else if (playerid > currentPlayerId && playerid < nextHigherId)
             {
                 nextHigherId = playerid; // more than our ID and less than those found so far.
             }
         }

         //UnityEngine.Debug.LogWarning("Debug. " + currentPlayerId + " lower: " + lowestId + " higher: " + nextHigherId + " ");
         //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(currentPlayerId));
         //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(lowestId));
         //if (nextHigherId != int.MaxValue) UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(nextHigherId));
         return (nextHigherId != int.MaxValue) ? players[nextHigherId] : players[lowestId];
     }