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

"}" Expecting

Discussion in 'Scripting' started by Deatric, Jul 29, 2014.

  1. Deatric

    Deatric

    Joined:
    Jul 29, 2014
    Posts:
    5
    Hello

    I'm pretty new to all this so I was messing with some code and I just can not find whats wrong with it, I keeping getting a error of it expecting a "}" on line 29 when I indeed have one, or am I overlooking something?

    Thanks in advance.

    Code (csharp):
    1.  
    2.     private int maxconnections = 512;
    3.     private int serverport = 9955;
    4.  
    5.     public void OnGUI()
    6.     {
    7.         if(Network.peerType == NetworkPeerType.Disconnected)
    8.         {
    9.             if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
    10.             {
    11.                 Network.InitializeServer(maxconnections, serverPort);
    12.             }
    13.  
    14.             if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
    15.             {
    16.                 Network.Connect ("localhost", serverPort);
    17.             }
    18.         }
    19.  
    20.         if(Network.peerType == NetworkPeerType.Client)
    21.         {
    22.             GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
    23.         }
    24.  
    25.         if(Network.peerType == NetworkPeerType.Server)
    26.         {
    27.             GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length)
    28.        }
    29.     }
    30.  
     
  2. v3n0mou5

    v3n0mou5

    Joined:
    Jan 8, 2014
    Posts:
    14
    hey man i fixed it for you, your forgot a ";"

    Happy coding ;)
    Code (CSharp):
    1.     private int maxconnections = 512;
    2.     private int serverport = 9955;
    3.    
    4.     public void OnGUI()
    5.     {
    6.         if(Network.peerType == NetworkPeerType.Disconnected)
    7.         {
    8.             if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
    9.             {
    10.                 Network.InitializeServer(maxconnections, serverPort);
    11.             }
    12.            
    13.             if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
    14.             {
    15.                 Network.Connect ("localhost", serverPort);
    16.             }
    17.         }
    18.        
    19.         if(Network.peerType == NetworkPeerType.Client)
    20.         {
    21.             GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
    22.         }
    23.        
    24.         if(Network.peerType == NetworkPeerType.Server)
    25.         {
    26.             GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length); //<<< right here
    27.         }
    28.     }
     
  3. Deatric

    Deatric

    Joined:
    Jul 29, 2014
    Posts:
    5
    Hmm, yeah I did miss that. But i'm still getting that error :/ Its a Parsing error.
    I don't know if a exact view of what i'm seeing will help:
     

    Attached Files:

    Last edited: Jul 29, 2014
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Looks like you accidentally hit Ctrl-B in your MonoDevelop at some point. That makes it compile the code internally, where it spotted the error, and you haven't re-compiled in MonoDevelop since for it to notice that you've fixed it.

    Now that you have fixed it, hit Ctrl-B again and the error flags should go away.

    Just to be clear, you don't need to compile in MonoDevelop. Unity compiles your code for itself. I know you probably didn't do it on purpose (and it can't hurt anything), but just a heads up in case. Unity's console will flag errors for you as well, and double clicking them there will take you to their line in MonoDevelop.
     
  5. Deatric

    Deatric

    Joined:
    Jul 29, 2014
    Posts:
    5
    Thank you for replying. Well as I was trying to figure out this error for myself I ended up debugging to try and figure out the problem by doing a trial and error session. Still no luck, the missing ";" was however a error, which is now fixed but I still have the main error I can't get rid of. Heres a look at my Mono and Unity together showing the error:
     

    Attached Files:

  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    You're going to have to post the whole file. Chances are there's a missing } elsewhere.
     
  7. Deatric

    Deatric

    Joined:
    Jul 29, 2014
    Posts:
    5
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetworkManager : MonoBehaviour
    5. {
    6.     private int maxconnections = 512;
    7.     private int serverport = 9955;
    8.  
    9.     public void OnGUI()
    10.     {
    11.         if(Network.peerType == NetworkPeerType.Disconnected)
    12.         {
    13.             if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
    14.             {
    15.                 Network.InitializeServer(maxconnections, serverPort);
    16.             }
    17.  
    18.             if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
    19.             {
    20.                 Network.Connect ("localhost", serverPort);
    21.             }
    22.         }
    23.  
    24.         if(Network.peerType == NetworkPeerType.Client)
    25.         {
    26.             GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
    27.         }
    28.  
    29.         if(Network.peerType == NetworkPeerType.Server)
    30.         {
    31.             GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length);
    32.        }
    33.     }
    34.  
     
  8. v3n0mou5

    v3n0mou5

    Joined:
    Jan 8, 2014
    Posts:
    14
    hmm man its weird, i dont get that error when i copy ure script.
     
  9. Deatric

    Deatric

    Joined:
    Jul 29, 2014
    Posts:
    5
    Really? Hmm.
     
  10. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Hehe, indeed. If that is in fact the whole script then it is in fact missing a '}'.

    OnGUI has a closing brace, but NetworkManager does not.

    In v3n0m0us's defence, it's quite possible that MonoDevelop either already had it (it's included in the default template) or auto-closed the brace when he copied the code in.
     
  11. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    are you using vs? it auto closes }
     
  12. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Line 5 has a {
    Line 34 does not have a }

    How can you miss this with such neat and clear tabbing