"}" Expecting

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.

    private int maxconnections = 512;
    private int serverport = 9955;

    public void OnGUI()
    {
        if(Network.peerType == NetworkPeerType.Disconnected)
        {
            if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
            {
                Network.InitializeServer(maxconnections, serverPort);
            }

            if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
            {
                Network.Connect ("localhost", serverPort);
            }
        }

        if(Network.peerType == NetworkPeerType.Client)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
        }

        if(Network.peerType == NetworkPeerType.Server)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length)
       }
    }

hey man i fixed it for you, your forgot a “;”

Happy coding :wink:

    private int maxconnections = 512;
    private int serverport = 9955;
   
    public void OnGUI()
    {
        if(Network.peerType == NetworkPeerType.Disconnected)
        {
            if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
            {
                Network.InitializeServer(maxconnections, serverPort);
            }
           
            if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
            {
                Network.Connect ("localhost", serverPort);
            }
        }
       
        if(Network.peerType == NetworkPeerType.Client)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
        }
       
        if(Network.peerType == NetworkPeerType.Server)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length); //<<< right here
        }
    }

Hmm, yeah I did miss that. But i’m still getting that error :confused: Its a Parsing error.
I don’t know if a exact view of what i’m seeing will help:

1715453--108116--gfuhjgj.png

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.

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:

1715473--108117--Parsing error.png

You’re going to have to post the whole file. Chances are there’s a missing } elsewhere.

using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour
{
    private int maxconnections = 512;
    private int serverport = 9955;

    public void OnGUI()
    {
        if(Network.peerType == NetworkPeerType.Disconnected)
        {
            if(GUI.Button (new Rect(100, 100, 100, 30), "Server"))
            {
                Network.InitializeServer(maxconnections, serverPort);
            }

            if(GUI.Button (new Rect(200, 100, 100, 30), "Client"))
            {
                Network.Connect ("localhost", serverPort);
            }
        }

        if(Network.peerType == NetworkPeerType.Client)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Connected! Flawless!");
        }

        if(Network.peerType == NetworkPeerType.Server)
        {
            GUI.Label (new Rect(100, 100, 400, 30), "Clients Connected: " + Network.connections.Length);
       }
    }

hmm man its weird, i dont get that error when i copy ure script.

Really? Hmm.

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.

are you using vs? it auto closes }

Line 5 has a {
Line 34 does not have a }

How can you miss this with such neat and clear tabbing