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 static bool JoinRoom(string roomName, bool createIfNotExists)
     {
         if (connectionStateDetailed == PeerState.Joining || connectionStateDetailed == PeerState.Joined || connectionStateDetailed == PeerState.ConnectedToGameserver)
         {
             Debug.LogError("JoinRoom aborted: You can only join a room while not currently connected/connecting to a room.");
         }
         else if (room != null)
         {
             Debug.LogError("JoinRoom aborted: You are already in a room!");
         }
         else if (roomName == string.Empty)
         {
             Debug.LogError("JoinRoom aborted: You must specifiy a room name!");
         }
         else
         {
             if (offlineMode)
             {
                 offlineModeRoom = new Room(roomName, null);
                 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
                 return true;
             }
             else
             {
                 return networkingPeer.OpJoinRoom(roomName, null, null, createIfNotExists);
             }
         }

         return false; // offline and OpJoin both return but the error-cases don't
     }