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 JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
     {
         if (offlineMode)
         {
             if (offlineModeRoom != null)
             {
                 Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another.");
                 return false;
             }

             offlineModeRoom = new Room(roomName, roomOptions);
             NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom); // in offline mode you create, too for JoinOrCreateRoom
             NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
             return true;
         }


         if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
         {
             Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
             return false;
         }

         if (string.IsNullOrEmpty(roomName))
         {
             Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?");
             return false;
         }

         return networkingPeer.OpJoinRoom(roomName, roomOptions, typedLobby, true);
     }