Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can someone tell me how to stop getting these problems

Discussion in 'Editor & General Support' started by dadead1601, May 29, 2014.

  1. dadead1601

    dadead1601

    Joined:
    May 28, 2014
    Posts:
    6
    Errors: http://gyazo.com/50c9057f7757a0952b61d80fadfa4116

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. using System.Collections;
    4.  
    5.  
    6.  
    7.  
    8.  
    9. /// <summary>
    10.  
    11. /// Makes the multiplayer
    12.  
    13. /// </summary>
    14.  
    15.  
    16.  
    17. public class MultiplayerScript : MonoBehaviour {
    18.  
    19.        
    20.    
    21.     //Variables Start _________________________
    22.    
    23.    
    24.    
    25.     private string titleMessage = "GTGD Series 1 Prototype";
    26.    
    27.     private string connectToIP = "127.0.0.1";
    28.    
    29.     private int connectionPort = 26500;
    30.    
    31.     private bool useNAT = false;
    32.    
    33.     private string ipAddress;
    34.    
    35.     private string port;
    36.    
    37.     private int numberOfPlayers = 10;
    38.    
    39.     public string playerName;
    40.    
    41.     public string serverName;
    42.    
    43.     public string serverNameForClient;
    44.    
    45.     private bool iWantToSetupAServer;
    46.    
    47.     private bool iWantToConnectToAServer;
    48.    
    49.    
    50.    
    51.     //These cariables are used to define the main
    52.    
    53.     //window.
    54.    
    55.    
    56.    
    57.     private Rect connectionWindowRect;
    58.    
    59.     private int connectionWindowWidth = 400;
    60.    
    61.     private int connectionWindowHeight = 290;
    62.    
    63.     private int buttonHeight = 60;
    64.    
    65.     private int leftIndent;
    66.    
    67.     private int topIndent;
    68.  
    69.     //Variables End ________________________________
    70.  
    71. }
    72.    
    73.    
    74.    
    75.    
    76.    
    77.     // Use this for initialization
    78.    
    79.         void Start ()
    80.     {
    81.        
    82.         serverName = PlayerPrefs.GetString ("serverName");
    83.  
    84.         if(serverName == "")
    85.         {
    86.         serverName = "Server";
    87.         }
    88.     }
    89.  
    90.    
    91.    
    92.    
    93.     // Update is called once per frame
    94.    
    95.     void Update () {
    96.        
    97.        
    98.        
    99.     }
    100.    
    101.    
    102.    
    103.    
    104.    
    105.     void ConnectWindow(int windowID)
    106.     {
    107.         //Leave a gap from the header.
    108.        
    109.        
    110.  
    111.         GUILayout.Space(15);
    112.        
    113.        
    114.        
    115.         //When the player launches the game they have the option
    116.        
    117.         //to create a server or join a server. The variabels
    118.        
    119.         //iWantToSetupAServer and iWantToConnectToAServer start as
    120.        
    121.         //false so the player presencted with two buttons
    122.        
    123.         //"Setup my server" and "Connect to a server".
    124.        
    125.    
    126.  
    127.         if(iWantToSetupAServer == false  iWantToConnectToAServer == false)
    128.         {
    129.            
    130.             if(GUILayout.Button("Setup a server", GUILayout.Height (buttonHeight)))
    131.             {  
    132.            
    133.                
    134.                 iWantToSetupAServer = true;
    135.                
    136.             }
    137.            
    138.            
    139.            
    140.             GUILayout.Space(10);    
    141.            
    142.            
    143.            
    144.             if(GUILayout.Button("Connect to a server", GUILayout.Height(buttonHeight)))
    145.                
    146.             {
    147.                
    148.                 iWantToConnectToAServer = true;
    149.                
    150.             }
    151.            
    152.            
    153.  
    154.             GUILayout.Space(10);
    155.            
    156.            
    157.            
    158.             if(Application.isWebPlayer == false  Application.isEditor == false)
    159.             {  
    160.  
    161.                
    162.                 if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
    163.                    
    164.                 {
    165.                    
    166.                     Application.Quit();
    167.                    
    168.                 }
    169.                
    170.             }
    171.            
    172.         }
    173. }
    174.        
    175.  
    176.  
    177.  
    178.     if(iWantToSetupAServer == true)
    179.         {  
    180.         //The user can type a name for their server into
    181.         //the textfield.
    182.  
    183.         GUILayout.Label("Enter a name for your server");
    184.  
    185.         serverName = GUILayout.TextField(serverName);
    186.  
    187.  
    188.         GUILayout.Space(5);
    189.  
    190.         //The user can type in the Port number for their server
    191.         //into textfield. We defined a default value above in the
    192.         //variabels as 26500.
    193.  
    194.         GUILayout.Label("Server Port");
    195.  
    196.         connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString ()));
    197.  
    198.         GUILayout.Space(10);
    199.  
    200.         if(GUILayout.Button("Start my own server", GUILayout.Height(30)))
    201.         {
    202.             //create the server
    203.  
    204.             Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
    205.  
    206.             //save the servername using playerprefs.
    207.  
    208.             PlayerPrefs.SetString("ServerName", serverName);
    209.  
    210.             iWantToSetupAServer = false;
    211.        
    212.             }
    213.             if(GUILayout.Button("Go Back", GUILayout.Height(30)))
    214.             {
    215.                 iWantToSetupAServer = false;
    216.             }
    217.         }
    218.  
    219.  
    220.    
    221.  
    222.     void OnGUI()
    223.     {
    224.        
    225.         //If the player disconnected then run the ConnectWindow function.
    226.        
    227.        
    228.        
    229.         if(Network.peerType == NetworkPeerType.Disconnected)
    230.         {
    231.            
    232.             //Determine the posistion of the window based on the width and
    233.            
    234.             //height of the screen. The window will be placed in the middle
    235.            
    236.             //of the screen
    237.            
    238.            
    239.            
    240.             leftIndent = Screen.width / 2 - connectionWindowWidth / 2;
    241.            
    242.            
    243.            
    244.             topIndent = Screen.height / 2 - connectionWindowHeight / 2;
    245.            
    246.            
    247.            
    248.             connectionWindowRect = new Rect (leftIndent, topIndent, connectionWindowWidth,
    249.                                              
    250.                                              connectionWindowHeight);
    251.        }
    252.      
    253.     }
     
    Last edited: May 29, 2014
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
  3. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    The screen shot shows that the compiler found an error on line 194. It's possible it found errors before this, and you did not include the first error in the screenshot. Assuming line 194 is the first error, then locate that line and work out what's wrong. Or, go over to Answers where there are many questions tagged with CS1519. From reading your code, I can't see a problem on line 194, which makes me think there is an error earlier in the code. Line 168 looks odd.
     
  4. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    As per your other thread, you have a block of random code (line 158 onwards) floating randomly outside of a function inside a class declaration and a bit of a mess with your bracket pairs at the bottom again. You also still have the random function name that I added for you to point out something-wasn't-right-around-here.

    I understand your learning to program (again, that's great), but coming to the forums every 10mins when you get compiler errors from the absolute basics, isn't going to teach you anything. Perhaps you need to find a good set of tutorials about the basics of programming :)
     
  5. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  6. dadead1601

    dadead1601

    Joined:
    May 28, 2014
    Posts:
    6
    Still can not figure this out been sitting here staring at it for 2hr now.
     
  7. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    First error I see is line 71 has a bracket where it shouldn't be. The close brackets for the class should be the very last character in the script.
     
  8. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    You actually had several brackets out of place which I fixed for you. All I did was fix your brackets and nothing else so I have no idea if it will work for you but it does compile now with no errors.

    p.s I have no idea why it added all those extra returns.

    Code (csharp):
    1.     using UnityEngine;
    2.  
    3.      
    4.  
    5.     using System.Collections;
    6.  
    7.      
    8.  
    9.      
    10.  
    11.      
    12.  
    13.      
    14.  
    15.      
    16.  
    17.     /// <summary>
    18.  
    19.      
    20.  
    21.     /// Makes the multiplayer
    22.  
    23.      
    24.  
    25.     /// </summary>
    26.  
    27.      
    28.  
    29.      
    30.  
    31.      
    32.  
    33.     public class MultiplayerScript : MonoBehaviour {
    34.  
    35.      
    36.  
    37.            
    38.  
    39.        
    40.  
    41.         //Variables Start _________________________
    42.  
    43.        
    44.  
    45.        
    46.  
    47.        
    48.  
    49.         private string titleMessage = "GTGD Series 1 Prototype";
    50.  
    51.        
    52.  
    53.         private string connectToIP = "127.0.0.1";
    54.  
    55.        
    56.  
    57.         private int connectionPort = 26500;
    58.  
    59.        
    60.  
    61.         private bool useNAT = false;
    62.  
    63.        
    64.  
    65.         private string ipAddress;
    66.  
    67.        
    68.  
    69.         private string port;
    70.  
    71.        
    72.  
    73.         private int numberOfPlayers = 10;
    74.  
    75.        
    76.  
    77.         public string playerName;
    78.  
    79.        
    80.  
    81.         public string serverName;
    82.  
    83.        
    84.  
    85.         public string serverNameForClient;
    86.  
    87.        
    88.  
    89.         private bool iWantToSetupAServer;
    90.  
    91.        
    92.  
    93.         private bool iWantToConnectToAServer;
    94.  
    95.        
    96.  
    97.        
    98.  
    99.        
    100.  
    101.         //These cariables are used to define the main
    102.  
    103.        
    104.  
    105.         //window.
    106.  
    107.        
    108.  
    109.        
    110.  
    111.        
    112.  
    113.         private Rect connectionWindowRect;
    114.  
    115.        
    116.  
    117.         private int connectionWindowWidth = 400;
    118.  
    119.        
    120.  
    121.         private int connectionWindowHeight = 290;
    122.  
    123.        
    124.  
    125.         private int buttonHeight = 60;
    126.  
    127.        
    128.  
    129.         private int leftIndent;
    130.  
    131.        
    132.  
    133.         private int topIndent;
    134.  
    135.      
    136.  
    137.         //Variables End ________________________________
    138.  
    139.      
    140.  
    141.    // }
    142.  
    143.        
    144.  
    145.        
    146.  
    147.        
    148.  
    149.        
    150.  
    151.        
    152.  
    153.         // Use this for initialization
    154.  
    155.        
    156.  
    157.             void Start ()
    158.  
    159.         {
    160.  
    161.            
    162.  
    163.             serverName = PlayerPrefs.GetString ("serverName");
    164.  
    165.      
    166.  
    167.             if(serverName == "")
    168.  
    169.             {
    170.  
    171.             serverName = "Server";
    172.  
    173.             }
    174.  
    175.         }
    176.  
    177.      
    178.  
    179.        
    180.  
    181.        
    182.  
    183.        
    184.  
    185.         // Update is called once per frame
    186.  
    187.        
    188.  
    189.         void Update () {
    190.  
    191.            
    192.  
    193.            
    194.  
    195.            
    196.  
    197.         }
    198.  
    199.        
    200.  
    201.        
    202.  
    203.        
    204.  
    205.        
    206.  
    207.        
    208.  
    209.         void ConnectWindow(int windowID)
    210.  
    211.         {
    212.  
    213.             //Leave a gap from the header.
    214.  
    215.            
    216.  
    217.            
    218.  
    219.      
    220.  
    221.             GUILayout.Space(15);
    222.  
    223.            
    224.  
    225.            
    226.  
    227.            
    228.  
    229.             //When the player launches the game they have the option
    230.  
    231.            
    232.  
    233.             //to create a server or join a server. The variabels
    234.  
    235.            
    236.  
    237.             //iWantToSetupAServer and iWantToConnectToAServer start as
    238.  
    239.            
    240.  
    241.             //false so the player presencted with two buttons
    242.  
    243.            
    244.  
    245.             //"Setup my server" and "Connect to a server".
    246.  
    247.            
    248.  
    249.        
    250.  
    251.      
    252.  
    253.             if(iWantToSetupAServer == false  iWantToConnectToAServer == false)
    254.  
    255.             {
    256.  
    257.                
    258.  
    259.                 if(GUILayout.Button("Setup a server", GUILayout.Height (buttonHeight)))
    260.  
    261.                 {  
    262.  
    263.                
    264.  
    265.                    
    266.  
    267.                     iWantToSetupAServer = true;
    268.  
    269.                    
    270.  
    271.                 }
    272.  
    273.                
    274.  
    275.                
    276.  
    277.                
    278.  
    279.                 GUILayout.Space(10);    
    280.  
    281.                
    282.  
    283.                
    284.  
    285.                
    286.  
    287.                 if(GUILayout.Button("Connect to a server", GUILayout.Height(buttonHeight)))
    288.  
    289.                    
    290.  
    291.                 {
    292.  
    293.                    
    294.  
    295.                     iWantToConnectToAServer = true;
    296.  
    297.                    
    298.  
    299.                 }
    300.  
    301.                
    302.  
    303.                
    304.  
    305.      
    306.  
    307.                 GUILayout.Space(10);
    308.  
    309.                
    310.  
    311.                
    312.  
    313.                
    314.  
    315.                 if(Application.isWebPlayer == false  Application.isEditor == false)
    316.  
    317.                 {  
    318.  
    319.      
    320.  
    321.                    
    322.  
    323.                     if(GUILayout.Button("Exit Prototype", GUILayout.Height(buttonHeight)))
    324.  
    325.                        
    326.  
    327.                     {
    328.  
    329.                        
    330.  
    331.                         Application.Quit();
    332.  
    333.                        
    334.  
    335.                     }
    336.  
    337.                    
    338.  
    339.                 }
    340.  
    341.                
    342.  
    343.             }
    344.  
    345.    // }
    346.  
    347.            
    348.  
    349.      
    350.  
    351.      
    352.  
    353.      
    354.  
    355.         if(iWantToSetupAServer == true)
    356.  
    357.             {  
    358.  
    359.             //The user can type a name for their server into
    360.  
    361.             //the textfield.
    362.  
    363.      
    364.  
    365.             GUILayout.Label("Enter a name for your server");
    366.  
    367.      
    368.  
    369.             serverName = GUILayout.TextField(serverName);
    370.  
    371.      
    372.  
    373.      
    374.  
    375.             GUILayout.Space(5);
    376.  
    377.      
    378.  
    379.             //The user can type in the Port number for their server
    380.  
    381.             //into textfield. We defined a default value above in the
    382.  
    383.             //variabels as 26500.
    384.  
    385.      
    386.  
    387.             GUILayout.Label("Server Port");
    388.  
    389.      
    390.  
    391.             connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString ()));
    392.  
    393.      
    394.  
    395.             GUILayout.Space(10);
    396.  
    397.      
    398.  
    399.             if(GUILayout.Button("Start my own server", GUILayout.Height(30)))
    400.  
    401.             {
    402.  
    403.                 //create the server
    404.  
    405.      
    406.  
    407.                 Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
    408.  
    409.      
    410.  
    411.                 //save the servername using playerprefs.
    412.  
    413.      
    414.  
    415.                 PlayerPrefs.SetString("ServerName", serverName);
    416.  
    417.      
    418.  
    419.                 iWantToSetupAServer = false;
    420.  
    421.            
    422.  
    423.                 }
    424.  
    425.                 if(GUILayout.Button("Go Back", GUILayout.Height(30)))
    426.  
    427.                 {
    428.  
    429.                     iWantToSetupAServer = false;
    430.  
    431.                 }
    432.  
    433.             }
    434.  
    435.      
    436.  
    437.     }
    438.  
    439.        
    440.  
    441.      
    442.  
    443.         void OnGUI()
    444.  
    445.         {
    446.  
    447.            
    448.  
    449.             //If the player disconnected then run the ConnectWindow function.
    450.  
    451.            
    452.  
    453.            
    454.  
    455.            
    456.  
    457.             if(Network.peerType == NetworkPeerType.Disconnected)
    458.  
    459.             {
    460.  
    461.                
    462.  
    463.                 //Determine the posistion of the window based on the width and
    464.  
    465.                
    466.  
    467.                 //height of the screen. The window will be placed in the middle
    468.  
    469.                
    470.  
    471.                 //of the screen
    472.  
    473.                
    474.  
    475.                
    476.  
    477.                
    478.  
    479.                 leftIndent = Screen.width / 2 - connectionWindowWidth / 2;
    480.  
    481.                
    482.  
    483.                
    484.  
    485.                
    486.  
    487.                 topIndent = Screen.height / 2 - connectionWindowHeight / 2;
    488.  
    489.                
    490.  
    491.                
    492.  
    493.                
    494.  
    495.                 connectionWindowRect = new Rect (leftIndent, topIndent, connectionWindowWidth,
    496.  
    497.                                                  
    498.  
    499.                                                  connectionWindowHeight);
    500.  
    501.            }
    502.  
    503.          
    504.  
    505.         }
    506.  
    507. }
     
  9. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    @drewradley props for helping the OP out. I do wonder if re-writing his code for him is the help he needs. (Give a man a fish and he can eat for a day. Teach a man to fish and he can feed for a lifetime.)
     
  10. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    True, true. I'll keep that in mind.