I don't get this. (Noob coder)

I don't get this. (Noob coder)

Postby tinyCreeper » 09 Jul 2013, 03:04

I keep getting this error.

Error CS1513
Message: } expected
Line: 40


Code: Select all
using System;

namespace MCDzienny
{
    public class CmdName : Command
    {
        public override string name { get { return "name"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p);
                return;
            }
            string[] split = message.Trim().Split(' ');
            Player who = Player.Find(split[0]);
            if (who == null)
            {
                Player.SendMessage(p, "Player not found");
                return;

            if (split == "")
            {
                Player.GlobalMessage(who.PublicName + " is now " split[0]);
                who.PublicName = split[0];
            }
            try
            {
                if (p.group.Permission >= LevelPermission.Operator)
                {
                    Player.GlobalMessage(who.PublicName + " is now " + split[1]);
                    who.PublicName = split[1];
                }
            }
            catch { Help(p); }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/%aname %e[player] [name] -- Changes someone's name!");
        }
    }
}


I could be completely messing something up, I'm not sure lol, I'm very new to this.
tinyCreeper
 
Posts: 48
Joined: 05 Jul 2013, 12:21

Re: I don't get this. (Noob coder)

Postby tinyCreeper » 09 Jul 2013, 03:04

btw, I didn't make this whole cmd, I just added some stuff to it.
tinyCreeper
 
Posts: 48
Joined: 05 Jul 2013, 12:21

Re: I don't get this. (Noob coder)

Postby ismellike » 09 Jul 2013, 03:41

The closing bracket of if(who==null) is not there.
Also, remove the if(split=="")
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: I don't get this. (Noob coder)

Postby Warren1001 » 10 Jul 2013, 05:45

Just to explain things to you so you understand why it's wrong, instead of just knowing its wrong; every statement (if, else, foreach, while, do, etc) has two bracets, one that opens it and one that closes it.
You'll see at the beginning of commands that it has it by default, for example:
Spoiler:

As you can see, below the namespace MCDzienny there is a opening bracket and if go straight down from it, you'll fnd a closing one. Those are grouped together. everything inside those is one part.

the top part, with the "public override etcetc { get { return etcetc; } }" you can write the things in that format, or simply like its shown in the public override void Use(player p, string message). It's recommended to write in the void use way so you dont mess up. your error is coming from not having the end bracket, so instead the system uses the closest accessable one, and ends up in a chain, and the very last one technically isnt tehre, so the command is technically not finished. it hasnt been stopped or cut off... if you understand what im saying. (sorry i got too lazy to type correctly)
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: I don't get this. (Noob coder)

Postby tinyCreeper » 10 Jul 2013, 20:42

Yah I knew that, i just completely missed that I forgot the closing bracket and was getting thrown off by what line it was saying the error on.
tinyCreeper
 
Posts: 48
Joined: 05 Jul 2013, 12:21


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron